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}$
Related
Every time this is asked, the answer is to use negative lookahead like so: (?!x)
Well unfortunately I must implement an American Express check in vb6, which does NOT support negative lookaheads or negative look behinds.
Is it possible to match everything except 34, 37 using the oldest imaginable implementation of regular expressions?
I expected this sort of thing to work:
^[1,2,4-9][1-3,5-6,8-9][0-9]{13}$
I've been able to match AmEx with this expression of course: ^3[47][0-9]{13}$ but I haven't found a way to inverse the validation rule.
Here is my validator setup:
<asp:RegularExpressionValidator
ID="AmExValidator"
Display="None"
ControlToValidate="txtCreditCardNumber"
ValidationExpression="^[1,2,4-9][1-3,5-6,8-9][0-9]{13}$"
ErrorMessage="American Express cards are not accepted."
ValidationGroup="Payment"
runat="server">
</asp:RegularExpressionValidator>```
You can use
^([0-24-9][0-9]|3[0-35689])[0-9]{13}$
See the regex demo. Details:
^ - start of string
([0-24-9][0-9]|3[0-35689]) - 00 to 29 and 40 to 99, or 3 followed with a digit other than 4 and 7
[0-9]{13} - thirteen digits
$ - end of string.
I use a regular expression to validate a Dutch mobile phone number:
^((\+316|06|00316){1}\\s?-?\s?[1-9]{1}[0-9]{7})$
So the number should start with 06 or +316 or 00316 followed by 8 digits (not starting with a 0)
Now I have to extend the validation so it also allows for international numbers from outside The Netherlands.
I want to keep it simple so I was thinking:
If it not starts with 06 or +316 or 00316 then it should start with '00dd' or '+dd' where dd!=31 followed by 8 till 12 digits.
so 0032127384562 should match but 00317198765432 not (because it starts with 0031 but not 00316)
Does anybody know how to do this?
The regex for the international number is:
^00(?!31)[0-9]{2}\s?-?\s?[1-9][0-9]{7,11}$
or, if you can't use lookahead:
^00([0-24-9][0-9]|3[02-9])\s?-?\s?[1-9][0-9]{7,11}$
You can concatenate it with | and the Dutch regex.
Be aware that there is a typo in your regex at \\.
Regular expression in java for a string which can contain 2 digits & 10 alphabets irrespective of their position in String
Examples of string are:
1abcdefghij2
12abcdefghij
abcdefghij12
abcdefg1hij2
ab12cdefghij
Is it possible?
I think the regex you are looking for is like this.
Regex: ^(?=\D*\d\D*\d\D*$)[a-zA-Z0-9]{12}$
Explanation:
(?=\D*\d\D*\d\D*$) checks for presence of 2 digits.
[a-zA-Z0-9]{12} makes sure that the total length is 12.
Since presence of 2 digits is already checked obviously there will be 10 alphabets.
Regex101 Demo
Edit #1: Edited regex on Sebastian Proske's advice from
^(?=.*\d.*\d)[a-z0-9]{12}$ to ^(?=\D*\d\D*\d\D*$)[a-zA-Z0-9]{12}$
Yes, it's possible.
[12a-j]+ for strings not limited by length and [12a-j]{12} for string exactly 12 characters long.
You can test it here.
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'm trying to write a regex pattern that will find numbers with two leading 00's in it in a string and replace it with a single 0. The problem is that I want to ignore numbers in parentheses and I can't figure out how to do this.
For example, with the string:
Somewhere 001 (2009)
I want to return:
Somewhere 01 (2009)
I can search by using [00] to find the first 00, and replace with 0 but the problem is that (2009) becomes (209) which I don't want. I thought of just doing a replace on (209) with (2009) but the strings I'm trying to fix could have a valid (209) in it already.
Any help would be appreciated!
Search one non digit (or start of line) followed by two zeros followed by one or more digits.
([^0-9]|^)00[0-9]+
What if the number has three leading zeros? How many zeros do you want it to have after the replacement? If you want to catch all leading zeros and replace them with just one:
([^0-9]|^)00+[0-9]+
Ideally, you'd use negative look behind, but your regex engine may not support it. Here is what I would do in JavaScript:
string.replace(/(^|[^(\d])00+/g,"$10");
That will replace any string of zeros that is not preceded by parenthesis or another digit. Change the character class to [^(\d.] if you're also working with decimal numbers.
?Regex.Replace("Somewhere 001 (2009)", " 00([0-9]+) ", " 0$1 ")
"Somewhere 01 (2009)"