How to validate the email validation using REGULAR EXPRESSION

Posted by Graha under Regular Expressions on 7/15/2011 | Points: 10 | Views : 145421 | Status : [Member] | Replies : 13
[B]what is regular Expression?

What is the syntax?

how it can be used?

Please tell answer for that question....

because I need to be valiate the email validation


using Regular expression....





Responses

Posted by: Chandru_ra on: 7/15/2011 [Member] Starter | Points: 25

Up
0
Down
reqular expession one of the validate control for asp.net. its used for email validate,pinnumbervalidate, url validtate, special symbol validate..etc..
example for email validate
<asp:RegularExpressionValidator ID="revEmail" runat="server"
ErrorMessage="Please enter in email format." ControlToValidate="txtEmail"
SetFocusOnError="true"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="A" ForeColor="" CssClass="Validation-Msg" Display="Dynamic"></asp:RegularExpressionValidator>


chandru

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kapsystem on: 7/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

The RegularExpressionValidator control is used to ensure that an input value matches a specified pattern.

Syntax for Regular Expression Validator

<asp:TextBox ID="txtEmailID" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revEmailID" runat="server"
ControlToValidate="txtEmailID"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>

Regards,
Web Designing Company[http://www.kapsystem.com/LINK]

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Graha on: 7/16/2011 [Member] Starter | Points: 25

Up
0
Down
thanks...

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.biswas on: 9/5/2011 [Member] Platinum | Points: 25

Up
0
Down
Try this

private bool IsValidEmail(string email)

{
string regexPattern = @"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
return new Regex(regexPattern, RegexOptions.IgnoreCase).IsMatch(email);
}


Hope this helps.

Thanks

Best Regards,
Niladri Biswas

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Taanu51 on: 9/6/2011 [Member] Starter | Points: 25

Up
0
Down
you can use client side validations or server side validations for regular expressions...its better to use client side validations..check out this link
it may helps you

http://www.developerscode.com/2011/02/client-side-validations-using.html

Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 6/29/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi,

Try this. it will hlp you..

 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Enter valid Email Id"
ControlToValidate="TextBox1" SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" > </asp:RegularExpressionValidator>


ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jeffie on: 6/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ,
you can use the below expression to validate the email
var emailFormat = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
you can use it as an Regualar Expression in javascript too

Thanks
http://www.alacraft.com.au/


Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/29/2012 [Member] Silver | Points: 25

Up
0
Down
http://regexlib.com/

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/29/2012 [Member] Silver | Points: 25

Up
0
Down
http://regexlib.com/REDetails.aspx?regexp_id=541

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Asavasamuel on: 3/18/2013 [Member] Starter | Points: 25

Up
0
Down
I found this library for verifying email addresses in .net:
http://www.kellermansoftware.com/p-37-net-email-validation.aspx


Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this

<asp:TextBox ID="TxtEmail" runat ="server" ></asp:TextBox>

<asp:RegularExpressionValidator ID="Req" runat ="server"
ControlToValidate ="TxtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
></asp:RegularExpressionValidator>

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Markford on: 2/15/2019 [Member] Starter | Points: 25

Up
0
Down
In any programming language, you can validate your email by using the regular expression. You can also use the Roadrunner Email. For instant support related to the Roadrunner Email please visit http://www.roadrunnersupport247.com/forgot-roadrunner-password/ for the best solution.

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shraddhapatel on: 3/13/2019 [Member] Starter | Points: 25

Up
0
Down
<html>
<head>
<title>Validation</title>
</head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<form>

<p>Enter an email address:</p>
<input id='email'>
<button type='submit' id='validate'>Validate!</button>

</form>
</body>
</html>
<h2 id='result'></h2>
<script>

function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}

function validate() {
var $result = $("#result");
var email = $("#email").val();
$result.text("");

if (validateEmail(email)) {
$result.text(email + " is valid :)");
$result.css("color", "green");
} else {
$result.text(email + " is not valid :(");
$result.css("color", "red");
}
return false;
}

$("#validate").bind("click", validate);

</script>

Dot Net Developer at iFour Technolab Pvt Ltd
www.ifourtechnolab.com

Graha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response