locked
regular expression for telephone no RRS feed

  • Question

  • how can i write regular expression for telephone no. which allow -,+,space, (,),- ,/

    Saturday, September 22, 2007 10:40 AM

Answers

  • Here's an example that should work:

    Code Block
    ^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$ 

    This regular expression for US phone numbers conforms to NANP A-digit and D-digit requirments (ANN-DNN-NNNN). Area Codes 001-199 are not permitted; Central Office Codes 001-199 are not permitted. Format validation accepts 10-digits without delimiters, optional parens on area code, and optional spaces or dashes between area code, central office code and station code. Acceptable formats include 2225551212, 222 555 1212, 222-555-1212, (222) 555 1212, (222) 555-1212, etc.


    (attribution: Don Johnston posted this at http://regexlib.com/DisplayPatterns.aspx?categoryId=7&cattabindex=2)

    Thursday, September 27, 2007 8:44 PM

All replies

  • Take a look at RegExlib.com. They have some good examples...

     

    Saturday, September 22, 2007 12:16 PM
  • Here's an example that should work:

    Code Block
    ^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$ 

    This regular expression for US phone numbers conforms to NANP A-digit and D-digit requirments (ANN-DNN-NNNN). Area Codes 001-199 are not permitted; Central Office Codes 001-199 are not permitted. Format validation accepts 10-digits without delimiters, optional parens on area code, and optional spaces or dashes between area code, central office code and station code. Acceptable formats include 2225551212, 222 555 1212, 222-555-1212, (222) 555 1212, (222) 555-1212, etc.


    (attribution: Don Johnston posted this at http://regexlib.com/DisplayPatterns.aspx?categoryId=7&cattabindex=2)

    Thursday, September 27, 2007 8:44 PM