regex for 10 digit phone number code example

Example 1: phone number regex

^[+0]{0,2}(91)?[0-9]{10}$

Example 2: 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");

Example 3: regex phone number 10 digit

^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

Tags:

Vb Example