Email Validation in JavaScript


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

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.


Copy this code and paste it in your HTML
  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>
  11.  
  12. <input type="text" id="email">
  13. <button onclick="alert(check_email(document.getElementById('email').value))">Validate</button>

URL: http://www.apphp.com/index.php?snippet=javascript-email-validation

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.