Javascript email validation


/ Published in: JavaScript
Save to your folder(s)




Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.