I'm trying to match exactly the following format:
+639201112222
09201112222
and this is all Ive tried so far:
(\+63|0)?\d{10}
the problem is that it match 2920111222 in 29201112222. How can i create a pattern that will match only the formats below?
+63XXXXXXXXXX
0XXXXXXXXXX
+63 or 0 plus 10 digit number only
where X are all digits from 0-9.
Thank you.
You want to do:
((\+63)|0)\d{10}
A regex for various phone number combinations (just quickly used rubular.com for this):
/(^0|[89]\d{2}-\d{3}\-?\d{4}$)|(^0|[89]\d{2}\d{3}\d{4}$)|(^63[89]\d{2}-\d{3}-\d{4}$)|(^63[89]\d{2}\d{3}\d{4}$)|(^[+]63[89]\d{2}\d{3}\d{4}$)|(^[+]63[89]\d{2}-\d{3}-\d{4}$)/
Validates:
0917-411-1111
0917-4111111
917-411-1111
9174111111
+63917-411-1111
63917-894-3454
639172342345
+639174111111
Here's a solution:
http://jsfiddle.net/kZMRx/
Related
I am having the following list of numbers which I would like to match:
44Th/s
40ksol/s
76Th/s
40Th/s
485Mh/s
432Mh/s
7Th/s
365Mh/s
33Th/s
3.1Th/s
6Th/s
1.1Gh/s
2.4Th/s
1.155Th/s
112.155Gh/s
I am using =regexreplace(A2,"[^\d]","") to match the numbers part. However, when a number looks like that 1.155Th/s I get back 1155.
I also tried the following regex \d*[.]\d*, which only gives me back:
3.1
1.1
24
1.155
112.155
Any suggestions how to also get the numbers part that looks like that 1.155, 112.155 or 3.1?
I appreciate your replies!
I suggest extracting the float/int value using REGEXEXTRACT:
=REGEXEXTRACT(A24, "\d+(?:\.\d+)?")
This will extract the first occurrence of a substring that starts with 1+ digits and is followed with an optional sequence of . and then 1+ digits.
Hello I should think of this regular expression:
The telephone number should begin with 087 OR 088 OR 089 and then it should be followed by7 digits:
This is what I made but it doesn't work correctly: it accepts only numbers which begin with 089
(087)|(088)|(089)[0-9]{7}";
/08[789]\d{7}/
that will match 087xxxxxxx, 088xxxxxxx, 089xxxxxxx numbers.
See it in action
Maybe /08[7-9][0-9]{7}/ is what you're searching for?
Autopsy:
08 - a literal 08
[7-9] - matches the numbers from 7-9 once
[0-9]{7} - matches the numbers from 0-9 repeated exactly 7 times
That said, you might prefer /^08[7-9][0-9]{7}$/ if your string is only the phone number. (^ means "the string MUST start here" and $ means "the string MUST end here").
Actually that will be far better regex for Bulgarian phone numbers:
/(\+)?(359|0)8[789]\d{1}(|-| )\d{3}(|-| )\d{3}/
It checks:
Phones that start with country code(+359) or 0 instead;
if the phone number use delimiters like - or space.
I tried it in https://regex101.com and it did not work against my test set. So I tweaked it a little bit with the below regex pattern:
^([+]?359)|0?(|-| )8[789]\d{1}(|-| )\d{3}(|-| )\d{3}$
How do I create a regex that matches telephones with or without spaces in the number?
I have found:
^\+?\d+$
From another post but how do I modify that to allow 0 or more spaces in the number?
The first thing you need to think is the exact format you want for phone numbers containing spaces. Eg:
+535 233 4444
Is that one OK? It means divided like: 3 3 4. You can adapt the following regex to your needs:
^\+?\d{3}\s?\d{3}\s?\{d}{4}$
Just change the quantifiers ({3}, {4}, etc) to change the group lengths.
This is one example:
/^(?:\s*\d{3})?\s*\d{3}\s*\d{4}\s*$/
There's a lot of ways to match telephone numbers (and a lot of valid telephone formats). Here's a simple regex to match "5555555555", "555 555 5555", "(555) 555-5555", "555-555-5555", or "555.555.5555"
^(?\d{3})?( |-|.)?\d{3}( |-|.)?\d{4}$
i want to validate my phone number with the regex for following formats.i have googled the things but i could not find the regex for following formats...
079-26408300 / 8200
(079) 26408300
079 264 083 00
9429527462
can anyone please guide me how can i do validate the phone number field for above formats?
I want to validate the phone number for only above formats as right now am using only following regex var phone_pattern = /^[a-z0-9]+$/i;
#Ali Shah Ahmed
var phone_pattern = "(\d{10})|(\d{3}-\d{8}\s/\s\d{4})|((\d{3}\s){3}\d{2})|((\d{3})\s\d{8})";
here is the way am checking if its valid
if (!phone_pattern.test(personal_phone))
{
$("#restErrorpersonalphone").html('Please enter valid phone number');
$("#personal_phone").addClass('borderColor');
flag = false;
} else {
$("#restErrorpersonalphone").html('');
$("#personal_phone").removeClass('borderColor');
}
its not working. Am I implementing in wrong way?
lets start with the simplest phone number 9429527462
As this has 10 characters and all are numbers, regex for it could be \d{10}
Now the next phone number 079 264 083 00. Regex for this pattern could be (\d{3}\s){3}\d{2}
First we are expecting a group of 3 digits and a space to repeat thrice (\d{3}\s){3}, this will cover 079 264 083 (space included in it), so left will be the last two characters which are handled using \d{2}
For the phone number (079) 26408300, \(\d{3}\)\s\d{8} regex could be use. The regex first looks for a opening bracket, then three digits inside it, and then the closing bracket. It then looks for a space, and then for 8 digits.
The phone number 079-26408300 / 8200 could be validated using regex \d{3}-\d{8}\s/\s\d{4}. It first looks for 3 digits then a -, then 8 digits followed by a space. Then looks for a / and then a space and then 4 digits.
If you wish to know a single regex for validating all the above patterns, do let me know.
Final combined regex would be:
/(\d{10})|(\d{3}-\d{8}\s\/\s\d{4})|((\d{3}\s){3}\d{2})|(\(\d{3}\)\s\d{8})/
Straightforward solution is simple, use |
String ex = "\\d{3}-\\d{8} / \\d{4}|\\(\\d{3}\\) \\d{8}|...
I am trying to match a group of numbers in regex that consist of one of the following:
1,2,3,4,5,6,7,8,9,10,11
But I am having trouble figuring out the regex.
For single digits this pattern worked fine "0|1|2|3|4|5|6|7|8|9" but it fails on double digit numbers. For example 12 passes as ok due to the regex finding the 1 in 12.
You can use begin and end anchors to force the whole string to be matched:
^(0|1|2|3|4|5|6|7|8|9|10|11)$
Which can be shortened to:
^(\d|10|11)$
This will work if you want to check if just one number is between 0 and 11.
^[0-9]$|^1?[0-1]$
If you want to match a string like:
1,2,3,12,32,5,1,6,8, 11
and match 0-11 then you can use the following:
(?<=,|^)([0-9]|1?[0-1])(?=,|$)
use this regex ^(0|1|2|3|4|5|6|7|8|9|(10)|(11))$