Email Validation 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.
[View All Snippets]
[View All Snippets]
Show Plain Text »
Demo:
- <script type="text/javascript">
- function check_email(email){
- var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,7})+$/;
- 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>
Demo: