Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
Created November 4, 2012 20:19
Show Gist options
  • Select an option

  • Save apphp-snippets/4013518 to your computer and use it in GitHub Desktop.

Select an option

Save apphp-snippets/4013518 to your computer and use it in GitHub Desktop.
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.
<script type="text/javascript">
/* Source: http://www.apphp.com/index.php?snippet=javascript-email-validation */
function check_email(email){
var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(reg.test(email)){
return true;
}else{
return false;
}
}
</script>
<input type="text" id="email">
<button onclick="alert(check_email(document.getElementById('email').value))">Validate</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment