Posted By

apphp-snippets on 03/04/13


email javascript validation

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


Email Validation in JavaScript

 / Published in: JavaScript


One of the important things about user input is to verify that the user has supplied the email that you have requested. The function below allows you to verify email address with easy.

  1. <script type="text/javascript">
  2. function check_email(email){
  3. var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  4. if(reg.test(email)){
  5. return true;
  6. }else{
  7. return false;
  8. }
  9. }
  10. </script>
  12. <input type="text" id="email">
  13. <button onclick="alert(check_email(document.getElementById('email').value))">Validate</button>

Report this snippet  

You need to login to post a comment.