Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,
I am using the REgEx "^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+[.])*(\.[a-zA-Z]{2,17})$"to validate Email but with that i am trying to resolve the MS Email Format.It satisfies all the format but i cant validate the below mentione format.

VB
Valid: js#internal@proseware.com
Valid: j_9@[129.126.118.1]


Valid Email Address :
VB
Valid: david.jones@proseware.com
Valid: d.j@server1.proseware.com
Valid: jones@ms1.proseware.com
Invalid: j.@server1.proseware.com
Invalid: j@proseware.com9
Valid: js#internal@proseware.com
Valid: j_9@[129.126.118.1]
Invalid: j..s@proseware.com
Invalid: js*@proseware.com
Invalid: js@proseware..com
Invalid: js@proseware.com9
Valid: j.s@server1.proseware.com


I am not that good at REgEX Stuff.Help me to achieve this
Posted

Hi hsakarp,

http://regexlib.com/RETester.aspx?regexp_id=90[^]

You can use the above link to test your Regular Expression by changing it for your own needs.

You can easily find the solution by changing the regex.
 
Share this answer
 
Comments
hsakarp 16-Aug-13 9:50am    
Thanks Thomas, But i am not that good at RegEx to resolve this complex(atleast for me) Expression.
VB
Valid: david.jones@proseware.com
Valid: d.j@server1.proseware.com
Valid: jones@ms1.proseware.com
Invalid: j.@server1.proseware.com
Invalid: j@proseware.com9
Valid: js#internal@proseware.com
Invalid: j..s@proseware.com
Invalid: js*@proseware.com
Invalid: js@proseware..com
Invalid: js@proseware.com9
Valid: j.s@server1.proseware.com

this one will stisfy all your requirement
C++
/^[a-z0-9\.#_]*[a-z.0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z]{2,6}$/i

C#
 except one >>
Valid: j_9@[129.126.118.1]

for this you have to custom your regex

Click here for more options

Click here

regards...:)
 
Share this answer
 
v2
Comments
lukeer 20-Aug-13 4:18am    
This exception is exactly what OP is asking how to achieve.
here is the code which will compare both the formats.UNfortunately i am using two loops to check the valid Email Address

C#
if (Input.match(/^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\_[a-zA-Z0-9-]+)*(\#[a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+[.])*(\.[a-zA-Z]{2,17})*(\.[a-zA-Z]{2,17})$/)) {

     It will test all the formats Except IP address
    }

else if (Input.match(/^[A-Za-z0-9._%#+-]+@\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]$/)) {
It will validate the IP address
    }



Here you can find a nice example for Email validation.

http://stackoverflow.com/questions/18273480/adding-ip-address-to-email-validation-regex/18280884?noredirect=1#18280884[^]

REgards,
Hsakarp.
 
Share this answer
 

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