Regular Expression Validation For Indian Phone Number and Mobile number

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

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

03595-259506 03592 245902 03598245785 

For mobile number

9775876662 0 9754845789 0-9778545896 +91 9456211568 91 9857842356 919578965389 

I would like the regular expression in one regex. I have tried the following regex but it is not working properly.

{^\+?[0-9-]+$} 

回答1:

For land Line Number

03595-259506 03592 245902 03598245785 

you can use this

\d{5}([- ]*)\d{6}

NEW for all ;)

OLD: ((\+*)(0*|(0 )*|(0-)*|(91 )*)(\d{12}+|\d{10}+))|\d{5}([- ]*)\d{6} NEW: ((\+*)((0[ -]+)*|(91 )*)(\d{12}+|\d{10}+))|\d{5}([- ]*)\d{6}  9775876662 0 9754845789 0-9778545896 +91 9456211568 91 9857842356 919578965389  03595-259506 03592 245902 03598245785 

this site is useful for me, and maby for you .;)http://gskinner.com/RegExr/



回答2:

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 


回答3:

Use the following regex

^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$ 

This will support the following formats:

  1. 8880344456
  2. +918880344456
  3. +91 8880344456
  4. +91-8880344456
  5. 08880344456
  6. 918880344456


回答4:

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 


回答5:

You Can Use Regex Like This:

   ^[0-9\-\(\)\, ]+$ 


回答6:

All Landline Numbers and Mobile Number

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



回答7:

This depends a lot on what you want the regex for: I had to import numbers from a rather dirty database to a new DB. So I wanted a liberal expression that just weeds out the completely wrong ones. Used this:

^\+?[\d(). -]{5,25}

Explaination

The phone number:

  • may or may not start with a plus.
  • could have one of these characters: ( ) . - space digit.
  • should have between 5 to 25 characters.

(Side Note: According to ITU, phone numbers are limited to max of 15 digits Phone Numbering Plan. A max=25 accomodates the special characters.)

Visual Explaination



回答8:

var phonereg = /^(\+\d{1,3}[- ]?)?\d{10}$/; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!