Search code examples
c#regexvalidationemail-validation

Regex not matching


Possible Duplicate:
Using a regular expression to validate an email address
Email Validation - Regular Expression

I am using following code to validate Email address in C#, but not sure why it fails always:

 var regEx = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})";

        if (Regex.IsMatch(regEx, "[email protected]", RegexOptions.IgnoreCase))
            return true;
        else
            return false;

Please can someone point out what I am missing here ?


Solution

  • You've got your IsMatch parameters the wrong way around; the first is the input, the second is the pattern.