Regular Expression Validation For Indian Phone Number and Mobile number

前端 未结 12 786
后悔当初
后悔当初 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: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
    

提交回复
热议问题