0

I am using the follwoing regular expression for email validation

@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"

Bit it accepts [][email protected][][] as a valid email.whats the pattern i should use? Is it possible to check that at client side?

7
  • 7
    I Knew How To Validate An Email Address Until I Read The RFC Commented Jan 24, 2013 at 9:26
  • Did you try to search a little on the subject before posting your question? Commented Jan 24, 2013 at 9:27
  • Dear @YannickBlondeau I tried a lot but when i entered before or later valid email address it accepts as a valid email Commented Jan 24, 2013 at 9:30
  • 1
    possible duplicate of Email Validation - Regular Expression Commented Jan 24, 2013 at 9:32
  • @Amol, I meant searching on StackOverflow to see if your question has already been answered... Commented Jan 24, 2013 at 9:50

1 Answer 1

2

If you want to validate an Email Address Regex is not the right choice.

Use MailAddress as recommended by SLaks

try 
{
   address = new MailAddress(address).Address;
   //address is valid here
} 
catch(FormatException) 
{
   //address is invalid
}

But if you are addicted to regex..just do this

.*@.*
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, is it possible to check at client side?
@Amol not possible since there are many corner cases where the regex would fail..you can try .*@.* at client side and then check it through MailAddress at server side..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.