Regular Expression Validation For Indian Phone Number and Mobile number

前端 未结 12 753
后悔当初
后悔当初 2020-12-01 09:26

I want to validate Indian phone numbers as well as mobile numbers. The format of the phone number and mobile number is as follows:

For land Line number



        
相关标签:
12条回答
  • 2020-12-01 10:16

    I use the following for one of my python project

    Regex

    (\+91)?(-)?\s*?(91)?\s*?(\d{3})-?\s*?(\d{3})-?\s*?(\d{4})
    

    Python usage

    re.search(re.compile(r'(\+91)?(-)?\s*?(91)?\s*?(\d{3})-?\s*?(\d{3})-?\s*?(\d{4})'), text_to_search).group()
    

    Explanation

    (\+91)? // optionally match '+91'
    (91)?   // optionally match '91'
    -?      // optionally match '-'
    \s*?    // optionally match whitespace
    (\d{3}) // compulsory match 3 digits
    (\d{4}) // compulsory match 4 digits
    

    Tested & works for

    9992223333
    +91 9992223333
    91 9992223333
    91999 222 3333
    +91999 222 3333
    +91 999-222-3333
    +91 999 222 3333
    91 999 222 3333
    999 222 3333
    +919992223333
    
    0 讨论(0)
  • 2020-12-01 10:17

    This works really fine:

    \+?\d[\d -]{8,12}\d
    

    Matches:

    03598245785
    9775876662
    0 9754845789
    0-9778545896
    +91 9456211568
    91 9857842356
    919578965389
    987-98723-9898
    +91 98780 98802
    06421223054
    9934-05-4851
    WAQU9876567892
    ABCD9876541212
    98723-98765
    

    Does NOT match:

    2343
    234-8700
    1 234 765
    
    0 讨论(0)
  • 2020-12-01 10:18

    you can implement following regex regex = '^[6-9][0-9]{9}$'

    0 讨论(0)
  • 2020-12-01 10:24

    For both mobile & fixed numbers: (?:\s+|)((0|(?:(\+|)91))(?:\s|-)*(?:(?:\d(?:\s|-)*\d{9})|(?:\d{2}(?:\s|-)*\d{8})|(?:\d{3}(?:\s|-)*\d{7}))|\d{10})(?:\s+|)

    Explaination:

    (?:\s+|)                    // leading spaces
    ((0|(?:(\+|)91))            // prefixed 0, 91 or +91
    (?:\s|-)*                   // connecting space or dash (-)
    (?:(?:\d(?:\s|-)*\d{9})|    // 1 digit STD code & number with connecting space or dash
    (?:\d{2}(?:\s|-)*\d{8})|    // 2 digit STD code & number with connecting space or dash
    (?:\d{3}(?:\s|-)*\d{7})|    // 3 digit STD code & number with connecting space or dash
    \d{10})                     // plain 10 digit number
    (?:\s+|)                    // trailing spaces
    

    I've tested it on following text

    9775876662
    0 9754845789
    0-9778545896
    +91 9456211568
    91 9857842356
    919578965389
    
    0359-2595065
    0352 2459025
    03598245785
    07912345678
    01123456789
    sdasdcsd
    +919898101353
    dasvsd0 
    +91 dacsdvsad
    davsdvasd
    
    0112776654
    
    0 讨论(0)
  • 2020-12-01 10:24

    You Can Use Regex Like This:

       ^[0-9\-\(\)\, ]+$
    
    0 讨论(0)
  • 2020-12-01 10:26

    All Landline Numbers and Mobile Number

    ^[\d]{2,4}[- ]?[\d]{3}[- ]?[\d]{3,5}|([0])?(\+\d{1,2}[- ]?)?[789]{1}\d{9}$

    0 讨论(0)
提交回复
热议问题