Regex Validator

Helpful code for verification:

  public bool isphonevalid(string phone)
        {
            string isphone = @"^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$";
            //return Regex.IsMatch(phone, @"^([0-9\(\)\/\+ \-]*)$");
            return Regex.IsMatch(phone, isphone);
        }
        private bool IsUrlValid(string url)
        {
            return Regex.IsMatch(url, @"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
        }
        bool isvalidname(string name)
        {
            return Regex.IsMatch(name,@"^[A-Za-z'\-\p{L}\p{Zs}\p{Lu}\p{Ll}\']+$");
        }
       public bool IsValidEmail(string email)
        {
            try
            {
                var addr = new System.Net.Mail.MailAddress(email);
                return true;
            }
            catch
            {
                return false;
            }
        }
     

Related Posts

Comments are closed.