Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Regular Expression for Email Format Validation using ASP.NET 4.0.

test@domainname.com,
test_123@domainname.com,
test.124@domainname.com,
test12.34_56test@domainname.com
test12.34_56test@domainname.co.in or uk or nz
test@196.27.2.1,

It will fail for rest all like it should not start with numbers,not special symbols except _(underscore). And also the domainname can't be in domain_name or domain-name or domain!@#$name. Rest all need to accepted.


I had tried by this (\w+[-+.]?)+@\w+([-.]\w+)*\.\w+([-.]\w+)* expression. But here I can access numbers, special characters in initial value.
Posted
Updated 5-Oct-12 3:00am
v2
Comments
OriginalGriff 5-Oct-12 6:05am    
And what have you tried?
Mannava Siva Aditya 5-Oct-12 9:00am    
I had tried by this (\w+[-+.]?)+@\w+([-.]\w+)*\.\w+([-.]\w+)* expression. But here I can access numbers, special characters in initial value.
Paresh Lahade 5-Oct-12 6:08am    
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
Mannava Siva Aditya 5-Oct-12 9:08am    
Can you be more presize and I want to make it in client side.
Keith Barrow 17-Jun-13 8:20am    
http://regexlib.com/Default.aspx has a searchable library of regexs, with descriptions of how they operate (including limitations etc) as well as ratings. Searching for e-Mail produces 8 pages of results at 20 results per page. About 20 of these have a 5-star rating. You can just peform a basic check on the client side and a full code-based check on the server if you get desperate...

U didnt mention your code for email pattern match..
Hence i m giving u following pattern try it out..n let me know its helping u or not.
C#
string pattern = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
 
Share this answer
 
Comments
Mannava Siva Aditya 5-Oct-12 9:02am    
Aysha Patel in your patter we can write, 12@gmail.com its been accepted. but an email should not start with numbers, or special symbols except _ (underscore)
Try on google[^] first Mannava, it will give you huge search results in quick time. And most of the threads will solve your problem quite easily. Take a look.
 
Share this answer
 
Comments
Mannava Siva Aditya 5-Oct-12 9:04am    
I had done the same but in most of all threads, when I test the email I am able to enter integers in initial, special symbols too. I want to restrict those we are not suppose to enter such things.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900