Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regular expression for phone number

Last post 09-13-2007, 12:09 PM by Lyndar. 4 replies.
Sort Posts: Previous Next
  •  09-12-2007, 1:36 AM 34726

    Regular expression for phone number

    Hi,

    I want to validate the phone number(landline or mobile) using a regular expression using Regularexpressionvalidator
    Phone number should be global (like used all over the world).
    It may contain special characters(Optional) like "hypen"(-), or "Paranthesis"().
    Ex: 086-104-2222
    or  (086)-104-2222
    or  0861042222      (US)

    or 9999999999       (Mobile)

    or 08026693647    (India)

    Can i get these done in a single expression
    Please Help  out !!

  •  09-12-2007, 11:59 AM 34739 in reply to 34726

    Re: Regular expression for phone number

    Here's something to try:

    ^\(?\d{3}\)?-?\d{3}-?\d{4}$

    Basically, this matches on 10 digits, with optional parantheses around the first 3 and optional dashes between the 3 sections.  Note that partial parantheses are not disallowed: so (800-312-7569 is valid according to this regex, as is 800)3121123

  •  09-12-2007, 12:33 PM 34752 in reply to 34739

    Re: Regular expression for phone number

    My suggestion:

     

    ^(\()?\d{2,3}(?(1)\))(?:-?\d{3}-?\d{4}|\d{11})$


    Eclesiastes
  •  09-13-2007, 2:06 AM 34776 in reply to 34752

    Re: Regular expression for phone number

    Syntax error in regular expression
  •  09-13-2007, 12:09 PM 34796 in reply to 34776

    Re: Regular expression for phone number

    It might help to specify which regex(es) caused the syntax error.
View as RSS news feed in XML