Regular expression for Landline Number [duplicate]
Possible Duplicate:
A comprehensive regex for phone number validation
My scenario:
i want to expect regular expression for following number
+(91)-(44)-96217000
+(91)-44-96217000
i try this expression is not working
static bool IsPhone(string s)
{
return Regex.IsMatch(s, @"\(?\d{2}\)?[\s\-]?\d{3}\-?\d{10}");
}
Well for one thing you're asking for a cluster of 3 digits when you expect 2 and a cluster of 10 when you expect 8 - I don't know what valid phone numbers are wherever you are but your examples won't match that.
I can also see a problem with your attempt to match the parens - with what you have both (91-44...
and 91)-44...
would be accepted. Regex OR |
is your friend here I think.
Can't help you much more without knowing your locale, and if I were you and knew that I'd google for an appropriate phone regex - these things are non-trivial.
精彩评论