Posted By

hotdiggity on 09/06/09


Tagged

email javascript validation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

guido


Javascript email validation


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2. function validateForm (submit) {
  3.  
  4. var errmsg = "Oops, you're required to complete the following fields! \n";
  5. if (submit.email.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
  6. errmsg = errmsg + " - Valid email\n";
  7. }
  8.  
  9. //Validate other form fields, etc, etc.
  10. if (submit.name.value=="") {
  11. errmsg = errmsg + " - Full Name\n";
  12. }
  13.  
  14. //alert if fields are empty and cancel form submit
  15. if (errmsg == "Oops, you're required to complete the following fields! \n") {
  16. sub.submit();
  17. }
  18. else {
  19. alert(errmsg);
  20. return false;
  21. }

Report this snippet  

You need to login to post a comment.