开发者

Regular expression for Landline Number [duplicate]

This question already has answers here: 开发者_如何学运维 Closed 12 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜