Search code examples
windows-phone-7

How to validate e-mail format in textbox?


I want to put validator so that if the user does not put the email id in correct format i.e. [email protected], a error message should pop-up. How do I put this validator for Windows Mobile?


Solution

  • using System;
    using System.Text.RegularExpressions;
    
      public static bool IsValidEmail(string strIn)
           {
               // Return true if strIn is in valid e-mail format.
               return Regex.IsMatch(strIn, 
                      @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" + 
                      @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"); 
           }