regex for only mobile numbers code example

Example 1: regex pattern for mobile number

/^(\+\d{1,3}[- ]?)?\d{10}$/

Example 2: regex for mobile number

^[6-9]\d{9}$

Example 3: regex for accepting mobile number only in 10 digit

Copy CodeRegex reg = new Regex(@"^[0-9]{10}$");
string inputOK = "9876543214";
string inputBad1 = "876543214";
string inputBad2 = "09876543214";
if (reg.IsMatch(inputOK)) Console.WriteLine("OK");
if (!reg.IsMatch(inputBad1)) Console.WriteLine("OK");
if (!reg.IsMatch(inputBad2)) Console.WriteLine("OK");

Tags:

Misc Example