I want regular expression for indian mobile numbers which consists of 10 digits.
The numbers which should match start with 9 or 8 or 7.
For example:
9882223456
8976785768
7986576783
It should not match the numbers starting with 1 to 6 or 0.
I want regular expression for indian mobile numbers which consists of 10 digits.
The numbers which should match start with 9 or 8 or 7.
For example:
9882223456
8976785768
7986576783
It should not match the numbers starting with 1 to 6 or 0.
^[789]\d{9}$
should do the trick.
^ #Match the beginning of the string
[789] #Match a 7, 8 or 9
\d #Match a digit (0-9 and anything else that is a "digit" in the regex engine)
{9} #Repeat the previous "\d" 9 times (9 digits)
$ #Match the end of the string
UPDATE
Some Telecom operators in india introduced new mobile number series which starts with digit 6.
for that use:
^[6-9]\d{9}$
^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$
Hi, This is regex for indian local mobile number validation and for Indian international .
starting with 9,8,7 you can add more as well.
you can test it using https://regex101.com/
Valid number are.
9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 -9883443344
+91- 9883443344
+91 - 9883443344
0091 - 9883443344
Here you go :)
^[7-9][0-9]{9}$
This Worked for me
^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$
Valid Scenarios:
+91-9883443344
9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 -9883443344
+91- 9883443344
+91 - 9883443344
0091 - 9883443344
7856128945
9998564723
022-24130000
080 25478965
0416-2565478
08172-268032
04512-895612
02162-240000
+91 9883443344
022-24141414
Invalid Scenarios:
WAQU9876567892
ABCD9876541212
0226-895623124
6589451235
0924645236
0222-895612
098-8956124
022-2413184
You may use this
/^(?:(?:\+|0{0,2})91(\s*|[\-])?|[0]?)?([6789]\d{2}([ -]?)\d{3}([ -]?)\d{4})$/
Valid Entries:
6856438922
7856128945
8945562713
9998564723
+91-9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 9883443344
+91-785-612-8945
+91 999 856 4723
Invalid Entries:
WAQU9876567892
ABCD9876541212
0226-895623124
0924645236
0222-895612
098-8956124
022-2413184
Validate it at https://regex101.com/
To reiterate the other answers with some additional info about what is a digit:
new Regex("^[7-9][0-9]{9}$")
Will match phone numbers written using roman numerals.
new Regex(@"^[7-9]\d{9}$", RegexOptions.ECMAScript)
Will match the same as the previous regex. When RegexOptions.ECMAScript
is specified \d
matches any roman numeral.
new Regex(@"^[7-9]\d{9}$")
Will match phone numbers written using any numerals for the last 9 digits.
The difference is that the first two patterns will only match phone numbers like 9123456789
while the third pattern also will match phone numbers like 9੧੨੩੪੫੬੭੮੯
.
So you can use \d
to match native numerals. However, if you want to limit the match for native numerals to only some (like 7-9) you need an additional step. For punjabi (India) to be able to match ੯੧੨੩੪੫੬੭੮੯
you can do it like this:
CultureInfo.GetCultureInfo("pa-IN").NumberFormat.NativeDigits.Skip(7).Take(3)
This will return the native numerals for 7-9. You can then join them together to form a "culture aware" regular expression for the digits 7-9.
i have used this regex in my projects and this works fine.
pattern="[6-9]{1}[0-9]{9}"
This is worked for me using JAVA script for chrome extension.
document.body.innerHTML = myFunction();
function myFunction()
{
var phonedef = new RegExp("(?:(?:\\+|0{0,2})91(\\s*[\\- ]\\s*)?|[0 ]?)?[789]\\d{9}|(\\d[ -]?){10}\\d", "g");
var str = document.body.innerHTML;
var res = str.replace(phonedef, function myFunction(x){return "<a href='tel:"+x.replace( /(\s|-)/g, "")+"'>"+x+"</a>";});
return res;
}
This covers following numbers pattern
9883443344
8888564723
7856128945
09883443344
0 9883443344
0-9883443344
919883443344
91 8834433441
91-9883443344
91 -9883443344
91- 9883443344
91 - 9883443344
91 -9883443344
+917878525200
+91 8834433441
+91-9883443344
+91 -9883443344
+91- 9883443344
+91 - 9883443344
+91 -9883443344
0919883443344
0091-7779015989
0091 - 8834433440
022-24130000
080 25478965
0416-2565478
08172-268032
04512-895612
02162-240000
022-24141414
079-22892350
- Mobile Number Validation [starting with 7,8,9]
func validate(value: String) -> Bool {
let PHONE_REGEX = "^[7-9][0-9]{9}$";
let phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
let result = phoneTest.evaluate(with: value)
return result
}
if validate(value: value) {
print("True")
}
var PHONE_REGEXP = /^[789]\d{9}$/;
this works for ng-pattern in angularjs or in javascript or any js framework
/(((^[\+,0][9][1])(((\s[0-9]{7,10})|(\S[0-9]{7,10}))|([-]\S[0-9]{7,10})))|((^[\+,0][2]{2,2})((\S[0-9]{7,8})|((([-])[0-9]{7,8})|(\s[0-9]{7,8})))))|(((^[6,7,8,9][0-9]{9,9}))|(^[0,\+](([9][1)|[6,7,8,9]))[0-9]{8,9}))/gm
I don't know if there is a simple expression for this but I have created this REGEX that validates all possible Indian numbers that contains (0 or +) then (91 or 22 (since I needed it for Maharashtra and second thing is that India have too many STD codes)) or directly searches for numbers starting with 6,7,8,9 that have/don't have a 0 in front of it .
(/[regex]/gm) is a trial for multi-line search you can remove it(//gm) if it fails to work/gives error.
Feel free to try it at regex101. My Project of this REGEX is here .
for Indian mobile number use this reg expression
^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){9}\d$
If you are trying to get multiple mobile numbers in the same text (re.findall
) then you should probably use the following. It's basically on the same lines as the ones that are already mentioned but it also has special look behind and look ahead assertions so that we don't pick a mobile number immediately preceded or immediately followed by a digit. I've also added 0?
just before capturing the actual mobile number to handle special cases where people prepend 0
to the mobile number.
(?<!\d)(?:\+91|91)?\W*(?P<mobile>[789]\d{9})(?!\d)
You may try it on pythex.org!
Solutions(^[789]\d{9}$
or ^[789][0-9]{9}$
) told by others have a one big flow (If that is used for form validation) It also validates numbers having more than 10 digit.
Basically our(Because I was also using this) regex finds a valid number placed anywhere in a string.Like this 1234569897969594
12345 .
The problem can be solved by additionally checking length of string containing number.
Like this if(regex.test(value) && value.length==10)/****do whatever*****/alert("Valid Number");
Note:- According to my tests , the regex.test(value)
tests only roman numerals for this expression ^[789]\d{9}$
in both firefox(mozilla) and chrome(webkit)
In Swift
extension String {
var isPhoneNumber: Bool {
let PHONE_REGEX = "^[7-9][0-9]{9}$";
let phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
let result = phoneTest.evaluate(with: self)
return result
}
}
For Laravel 5.4+
'mobile_number_1' => 'required|numeric|min:0|regex:/^[789]\d{9}$/' should do the trick