How to validate the email validation using REGULAR EXPRESSION

Posted by Graha under Regular Expressions on 7/15/2011 | Points: 10 | Views : 127558 | Status : [Member] | Replies : 11
[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

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

Login to post response