Checking if mobile phone is correct via Regex - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match Number

Description

Checking if mobile phone is correct via Regex

Demo Code


using System.Text.RegularExpressions;

public class Main{
        /// <summary>
		/// Checking if mobile phone is correct
		/// </summary>
		/// <param name="phone">Mobile phone number</param>
		/// <returns></returns>
		public static bool ValidateMobilePhone(string phone)
		{/*from w ww . j  ava2 s . c o m*/
			if(string.IsNullOrEmpty(phone))
				return false;

			return Regex.IsMatch(phone, @"^(8{1}\d{10})$") ||
				   Regex.IsMatch(phone, @"^(\+7{1}\d{10})$");
		}
}

Related Tutorials