Validate Indian Phone number with optional +91 or 0 preceeding 10 digits
You can use ^([0]|\+91)?\d{10}
as starts with 0
or +91
and 10 digits after that.
..but as you must have seen number starts with 7,8 or 9
Then, you should use ^([0]|\+91)?[789]\d{9}$
which means starts with 7
, 8
or 9
and follows 9
digits after that.
Some random matches;
+919802422462
08150166859
Regular Expression Validation For Indian Phone Number and Mobile number
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/
regular expression for Indian mobile numbers
^[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}$
Regular expression for Indian mobile phone numbers?
Try something like this:
^9\d{9}$
regular expression for indian phone number
You can try
^\+?[0-9-]+$
See it here on Regexr
The important parts are the anchors ^
and $
for the start and the end of the string. I added also \+?
at the start, to match an optional +
. The +
needs to be escaped since it is a special character in regex, the ?
after it makes it optional.
Of course this is a very simple pattern, be aware that e.g. "-----" would also be valid.
HTML5 phone number validation with pattern
How about this? /(7|8|9)\d{9}/
It starts by either looking for 7 or 8 or 9, and then followed by 9 digits.
Validate phone number with JavaScript
First off, your format validator is obviously only appropriate for NANP (country code +1) numbers. Will your application be used by someone with a phone number from outside North America? If so, you don't want to prevent those people from entering a perfectly valid [international] number.
Secondly, your validation is incorrect. NANP numbers take the form NXX NXX XXXX
where N
is a digit 2-9 and X
is a digit 0-9. Additionally, area codes and exchanges may not take the form N11
(end with two ones) to avoid confusion with special services except numbers in a non-geographic area code (800, 888, 877, 866, 855, 900) may have a N11
exchange.
So, your regex will pass the number (123) 123 4566 even though that is not a valid phone number. You can fix that by replacing \d{3}
with [2-9]{1}\d{2}
.
Finally, I get the feeling you're validating user input in a web browser. Remember that client-side validation is only a convenience you provide to the user; you still need to validate all input (again) on the server.
TL;DR don't use a regular expression to validate complex real-world data like phone numbers or URLs. Use a specialized library.
Regex for Mobile Number Validation
Satisfies all your requirements if you use the trick told below
Regex: /^(\+\d{1,3}[- ]?)?\d{10}$/
^
start of line- A
+
followed by\d+
followed by aor
-
which are optional. - Whole point two is optional.
- Negative lookahead to make sure
0
s do not follow. - Match
\d+
10 times. - Line end.
DEMO Added m
ultiline flag in demo to check for all cases
P.S. You really need to specify which language you use so as to use an if
condition something like below:
// true if above regex is satisfied and (&&) it does not (`!`) match `0`s `5` or more times
if(number.match(/^(\+\d{1,3}[- ]?)?\d{10}$/) && ! (number.match(/0{5,}/)) )
Validate Bangladeshi phone number with optional +88 or 01 preceeding 11 digits
I see you have tried but your regex is not accurate.
- You do not use an end of string
$
anchor (thus, even "abc" at the end will not prevent theIsMatch
from returningtrue
) - You are using
01
inside square brackets thus creating a character class, meaning either0
or1
. - No need in a capturing group here, a non-capturing is best for optional subpatterns.
- As has been pointed out in the follow up answers, the regex you are using is not actually meeting all the requirements for the Bangladeshi phone number, see Kobi's
^(?:\+?88|0088)?01[15-9]\d{8}$
answer.
In order to create a regex that will validate a string that has "optional +88
, 0088
or 01
preceeding 11 digits", you need something like:
@"^(?:(?:\+|00)88|01)?\d{11}$"
See RegexStorm demo
UPDATE
If you want to validate Bangladeshi phone numbers with this regex, nothing changes in the pattern (only \r?
is totally redundant), but if you plan to allow 13 or 11 digits after +88
or 01
, you need to use an alternation:
ng-pattern="/^(?:(?:\+|00)88|01)?\d{11}$/"
See demo
In Angular:
Validators.pattern('(?:(?:\\+|00)88|01)?\\d{11}')
// or
Validators.pattern(/^(?:(?:\+|00)88|01)?\d{11}$/)
Regex for Mobile Number with or without Country Code
From what I can see, this should work. The prefix is optional and is stored into the first match group, with the main number going into the second group.
^([0|\+[0-9]{1,5})?([7-9][0-9]{9})$
But if you can give us some test cases for each, it'd help us in giving you a working regex for what you want.
Props to SchlaWiener in the comments for the correct limit on the country code length.
Related Topics
Convert Byte Array to Wav File
Read and Parse a Json File in C#
How to Set a Cookie on Httpclient'S Httprequestmessage
Pass Array into ASP.NET Core Route Query String
What Regular Expression Would I Use to Remove Everything After the Second Backslash
Fetching Value from a Datatable into Datatable With Where Clause
How to Generate Unique Number of 8 Digits
How to Create ASP.NET Identity Tables in an Already Created Database Using Code First
How to Directly Print a Report Without Going Through Crystal Reports Viewer
Take String Before and After 'First' Space Character
How to Calculate the Average of Each Row in Multidimensional Array
How to Dynamically Adjust Table Column Width in Rdlc Report
Getting the Latest File Modified from Azure Blob
Restsharp Post Request - Body With X-Www-Form-Urlencoded Values
How to Loop Through All Fields in an Object in C#
C# Foreach (Property in Object)... Is There a Simple Way of Doing This
Formatting Date in Linq-To-Entities Query Causes Exception
How to Add a Run Button and Compile Button on the Toolbar in Visual Studio