asp.net - Adding IP Address to Email Validation RegEx -


i using 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 lead want validate per microsoft standard. need follow

http://msdn.microsoft.com/en-us/library/01escwtf(v=vs.100).aspx

in working fine per standard still facing issues

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

the above mentioned mail id still returning invalid. tried using regex used in page

^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$  

but getting error in server page. though pasted expression inside validation expression can't able accept characters.

note : using asp.net validators validating email.

description

to match both of email addresses in sample text, think rewrite expression this:

[a-z0-9._%#+-]+@(?:[a-z0-9.-]+\.[a-z]{2,4}|\[(?:(?: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]?)\])

enter image description here

if you're looking use validate string may contain email can add start/end of string anchors ^ , $.

example

live demo

sample text

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

matches

[0][0] = js#internal@proseware.com [1][0] = j_9@[129.126.118.1] 

Comments