Parvinder Singh
Parvinder Singh

Reputation: 43

Regular expression validation contain .com at the end of Email

I am working on the Regular Expression validation and validate on the email textbox. But the condition is use enter valid email but at the end of email use .com only i use this ValidationExpression="^\w+([-+.']\w+)*@abc.com$" it works but only for abc at the end of @ . But i need that use will enter any number or alphabet after @ .

Thanks

Upvotes: 0

Views: 2557

Answers (2)

Avinash Raj
Avinash Raj

Reputation: 174696

But i need that user will enter any number or alphabet after @

ValidationExpression = "^\w+([-+.']\w+)*@[A-Za-z\d]+\.com$"

Upvotes: 0

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56697

You should not validate email addresses using regular expressions. You will most probably get it wrong.

To validate whether a string ends with .com, use this regex:

\.com$

That's it. Example in C#:

if (Regex.IsMatch(eMail, @"\.com$", RegexOptions.IgnoreCase))

But then, in C#, you could just write

if (eMail.EndsWith(".com", StringComparson.InvariantCultureIgnoreCase))

Upvotes: 3

Related Questions