First of all i would say i have seen many example here and googled but none found that matches all the condition i am looking for some match top 3 not below some inbetween. Kindly let me know how to put all of them in one place.
(xxx)xxxxxxx (xxx) xxxxxxx (xxx)xxx-xxxx (xxx) xxx-xxxx xxxxxxxxxx xxx-xxx-xxxxx
Using as :
const string MatchPhonePattern = @"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}"; Regex rx = new Regex(MatchPhonePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); // Find matches. MatchCollection matches = rx.Matches(text); // Report the number of matches found. int noOfMatches = matches.Count; // Report on each match. foreach (Match match in matches) { tempPhoneNumbers= match.Value.ToString(); ; }
SAMPLE OUTPUT:
3087774825 (281)388-0388 (281)388-0300 (979) 778-0978 (281)934-2479 (281)934-2447 (979)826-3273 (979)826-3255 1334714149 (281)356-2530 (281)356-5264 (936)825-2081 (832)595-9500 (832)595-9501 281-342-2452 1334431660
Regular expression to allow numbers like +111 123 456 789: ^(\\+\\d{1,3}( )?)?(\\d{3}[ ]?){2}\\d{3}$
/^([+]\d{2})? \d{10}$/ This is how this regex for mobile number is working. + sign is used for world wide matching of number.
EPP-style phone numbers use the format + CCC . NNNNNNNNNN x EEEE , where C is the 1–3 digit country code, N is up to 14 digits, and E is the (optional) extension. The leading plus sign and the dot following the country code are required. The literal “x” character is required only if an extension is provided.
$ means "Match the end of the string" (the position after the last character in the string).
\(?\d{3}\)?-? *\d{3}-? *-?\d{4}
public bool IsValidPhone(string Phone) { try { if (string.IsNullOrEmpty(Phone)) return false; var r = new Regex(@"^\(?([0-9]{3})\)?[-.●]?([0-9]{3})[-.●]?([0-9]{4})$"); return r.IsMatch(Phone); } catch (Exception) { throw; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With