connectseekers.com

Tuesday, 4 August 2020

jQuery: Regex Use For Email Id Validate Validation

8/04/2020 - By Pranav Singh 0


This article will show you how you can validate an email address by regex using jQuery in your web application.

So first we will check the Regular expression to validate out email id.

"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"

Now let’s check the code. Here we will create a function which will validate the value as per passed regular expression.

function ValidateRegeex(regex, value) {
            var expre = new RegExp(regex);
            return expre.test(value);
    }

Now let’s use our validation function to validate the email id.

<input type="text" id="txtEmailId" />
<input type="button" value="Submit" onclick="javascript: ValudateEmaiId();"/>
<script>
    function ValudateEmaiId() {
    var regex = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    var value = $("#txtEmailId").val();
    var status = ValidateRegeex(regex, value);
    if (status == true) {
        alert("correct Email id");
    else {
        alert("Enter a Valid email id");
    }
}
</script>

Now check the output. As u enter valid or not a valid email id. you will get an error message.



As you enter correct email id you will get valid message.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top