Home > DeveloperSection > Forums > How to Validate Email address in javascript.
Ankit Singh

Total Post:341

Points:2389
Posted on    January-13-2016 11:08 PM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 279  View(s)
Rate this:
I want to to Validate Email address in javascript. How to Solve this problem please help me.


aditya kumar Patel

Total Post:250

Points:1782
Posted on    January-13-2016 11:14 PM

Javascript

    <script type="text/javascript">      
        $(document).ready(function (e) {
            function CheckEmail(email) {
                var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
                if (reg.test(email)) {
                    return true;
                }
                else {
                    return false;
                }
            }
            $('#btnok').click(function () {
                debugger;
                var email = $('#txtemail').val();
                if ($.trim(email).length == 0) {
                    alert('Please Enter Valid Email Address');
                    return false;
                }
                if (CheckEmail(email)) {
                    alert('Valid Email Address');
                    return false;
                }
                else {
                    alert('Invalid Email Address');
                    return false;
                }
            });
        });
</script>

HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-2.1.4.js"></script>
    <script type="text/javascript">      
        $(document).ready(function (e) {
            function CheckEmail(email) {
                var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
                if (reg.test(email)) {
                    return true;
                }
                else {
                    return false;
                }
            }
            $('#btnok').click(function () {
                debugger;
                var email = $('#txtemail').val();
                if ($.trim(email).length == 0) {
                    alert('Please Enter Valid Email Address');
                    return false;
                }
                if (CheckEmail(email)) {
                    alert('Valid Email Address');
                    return false;
                }
                else {
                    alert('Invalid Email Address');
                    return false;
                }
            });
        });
</script>
</head>
<body>
Email Address: <input type="text" id="txtemail"/><br/>
<input type="submit" id="btnok" Value="Submit" />
</body>
</html>

 


Modified On Jan-27-2016 05:55:37 AM

Don't want to miss updates? Please click the below button!

Follow MindStick