DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Ruslan has posted 8 posts at DZone. View Full User Profile

Check Email In Html Form

07.12.2007
| 18028 views |
  • submit to reddit
        // description of your code here

 <script type="text/javascript">
        function check_email(email_id,err_id){
            emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
            var err_mail='Email addres incorect!';
            if(emailRegExp.test(document.getElementById(email_id).value)){
                alert('true');
                return true;
            }else{
                document.getElementById(err_id).innerHTML=err_mail;
                alert(err_mail);
                return false;
            }
        }
    </script>

        <span id="err_msg" style="color: red;"></span>
    <form id="myForm" name="myForm" action="./register.php" method="post" onsubmit="return check_email('email','err_msg');">
        <input type="text" name="email" id="email"/>
        <input  type="submit" name="send" value="Send" />
    </form>