Mobile number field should not accept continous 1s, 2s etc - regex

I am trying to make a regexp for mobile number field such that, it would not accept the following type of inputs:
0000000000
1111111111
2222222222
like wise continuous same 10 digits. How to avoid accepting continuous similar ten digits as input for mobile number field?

A simple regex solution would be to capture the first digit and check if it's repeated 9 times and then take necessary actions. As you haven't mentioned any other tag I will leave it up to you to apply necessary actions.
Regex: /(\d)\1{9}/g Captures the first digit and if it's repeated 9 times then it matches pattern.
Regex101 Demo

You can use NOT REGEXP_LIKE(MOBILE_NO,'(.)\1{9,}') like below to suppress the unwanted input. But as suggested by Joachim, it is better to avoid it from front end if possible. Check this query and let me know if you get any issue.
WITH TBL(MOBILE_NO) AS
( SELECT '1111111111' FROM DUAL UNION
SELECT '1234444444' FROM DUAL UNION
SELECT '2222222222' FROM DUAL
)
SELECT * FROM TBL
where NOT REGEXP_LIKE(MOBILE_NO,'(\d)\1{9,}')
This will give output as 1234444444 and will skip other mobile_no, where there are 10 consecutive same numbers.
Referred this answer to get this.

Related

Regex to match a few specific 6 digit numbers (Indian pin codes)

I am using Google Forms to create an application form. Need to restrict submission for a few specific pin codes only. Here are some of the pin codes that I'm trying to limit it to.
560078 560070 560085 560069 560011 560080 560004 570070 560089 560060
First 4 digits are same in all the pin codes. I need to match the last two digits to the ones from a list. The list might end up being about 30, hence looking for a regex.
Which regex should I use for that?
You haven't specified the exact ranges. The pattern 5600(04|11|[6-8]\d) will match:
560004
560011
all the numbers from 560060 to 560089
It will need to be corrected according to the acceptable ranges.
It is suprising to see 570070 in the list when you note that the first 4 digits are always the same. Is it an error or an excpetion.

RegEx to clean VISA merchant names (remove random strings)

I am trying to develop a ReGex (.Net flavor), which I can use to clean VISA merchant names.
Examples:
Norton *AP1223506209 --> Norton *AP
Norton *AP1223511428
EUROWINGS VYJD6J_123001 --> EUROWINGS
EUROWINGS W6PDFI_125626
AER LINGUCB22QKM2 --> AER LINGUCB
AER LINGUCB248L2W
AIR FRANCE JWNCSC --> AIR FRANCE
AIR FRANCE K8L7TT
PAYPAL *AIRBNB HMQXBW --> PAYPAL *AIRBNB
PAYPAL *AIRBNB HMQXNZ
SAS 1174565172360 --> SAS
SAS 1174565172368
I would like to keep the first "name" part, but remove the second "gibberish" part.
The following Regex works for Norton and Air Lingu as well as for Eurowings and Air France, if they contain numbers in the gibberish part. It totally fails for PAYPAL *AIRBNB and other strings, that don't contain any numbers in the gibberish part, and also for SAS, probably because the name is too short / there are too many spaces:
Search:
([A-z *-]{2,50}[A-z]{2,50})(.{0,3}([0-9-]{0,3}[A-z *+.#-/]{0,3}){1,10})
Replace:
$1
Is there any way to make this work for gibberish parts that don't contain numbers? I have something like this in mind, but don't manage to create an according RegEx:
Group 1 (to keep)
Must contain consonants and vowels
Can contain few numbers, spaces or punctuation signs (e.g.: "7x7: Taxi Service")
Group 2 (to be removed)
Consists of sequences of numbers, letters and optional punctuation signs
OR: consists of consonants, only
OR: consists of numbers, only
Thanks for any help and best regards
Pesche
Edit:
If I add more examples, Lindens solution still works quite well, but does not recognize all of the examples or in some cases too much of the string. I tried to adjust it, but with my lacking skills didn't quite succeed:
https://regex101.com/r/7y9zGl/4
The following problems remain:
with a length of 6 for the last \w, longer patterns would not be matched in full length (e.g. after easyjet and after EMP Merchan). Increasing it, however, causes other strings to be truncated (e.g. AER LINGU, potentially also HOTELS.COM if > 12 was used).
The merchant names after PAYPAL * and GOOGLE * should not be deleted, as they are true merchant names. I tried to exclude strings containing GOOGLE * with a negative lookbehind, but it does not seem to work like that.
Whereas the merchant name after PAYPAL * should generally remain, in some cases it is followed by gibberish, e.g. PAYPAL *AIRBNB HMQXBW. If the negative lookbehind worked, those cases would no longer be cleaned.
if the merchant name is not followed by gibberish, part of the name itself may be deleted (e.g. EMP Merchan)
As the full list of merchant names is long and versatile, the approach to detect "gibberish" should be as generic as possible (i.e. not rely on a certain length of the gibberish part). Hence my original, now slightly modified "pattern":
Consists of sequences of numbers, letters and optional punctuation signs
OR: consists non or very few vowels (EASYJET 000ESJ5TWN -> the gibberish contains only one vowel, EASYJET 3 of them; PAYPAL *NITSCHKE -> NITSCHKE should not be matched, it contains 2 vowels)
OR: consists of numbers, only
Is such a thing even possible? The goal is to use SQL to clean the merchant names. If necessary, this can be done in several run throughs (for different kind of patterns).
Thx again!
Updated regex based on extended sample and desired results:
[\s*<]+\d+$|[\s*<]+(?![A-Z]{6}.*)\w*\d[\w>]*$|\d{6,}$|[\s*<]+[A-Z]{6}$|(?![A-Z]+$)(?<=[A-Z])\w{6}$
Demo
I cannot validate as I'm only on my phone, but can you try something like this?
^([0-9A-Za-z\*][ ]{0-2})
Take all the numbers, the letters (capital and minor) the star and max 2 spaces from the beginning of the line.
Please check the () but I guess the idea is here.
Sorry, it seems wrong when there is no double space.
You want to take all the char until 2 spaces or 2 numbers according to your examples.
.* {2}|.*[0-9]{2}
Is it better?
Regards,
Thomas

JSP input validate amount - possibly with REGEX

This is probably a simple question that has been solved many times. I am new to front end dev, so struggling with the validation part. I have a currency input that I used the following statement in JavaScript to only allow numbers. Can I just edit this or add a line to also only allow two decimals as you type?
$("input#amountToSave").on("blur keyup", function() {
this.value=this.value.replace(/[^0-9.]+/,'');
});
You can try something like this
^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$
Many currency expresssions allow leading zeros, thus $01.40 passes thru them. This expression kills them, except for 0 in the one's column. Works with or without commas and/or dollar sign. Decimals not mandatory, unless no zero in ones column and decimal point is placed. Allows $0.00 and .0 Keywords: money dollar currency
E.g.,
$1,234.50 | $0.70 | .7
Okay - I think I see the problem. I need a regex (it can be a simple one for the two decimals - for now I don't need it too complex and no Currency symbol is necessary) that is inverted. I now saw when reading up I am testing if the value is not 0-9 replace with space. So I need to add to that reg exp that if it is the 3rd decimal, then replace with space.

Regex to Limit Input To Only Numeric Values To 10 Occurences

I need help forming regex to limit user input to only numerics and only up to 10 occurrences.
I have regex that is working to keep input to numerics only, but I cannot limit it to up to 10.
Here is what I have:
^(0|[1-9][0-9]*)$
I am okay accepting negative numbers, decimals, and 0's. Any advice?
^\s*([0-9)+){0,10}\s*$
This basically says I want to 0 to 10 things, where each thing is all digits. I added the \s* on either side to allow the user to have put spaces before or after their numbers. This would accept things like
10 1231231 1231 1231 23112 123123
If what you really want is just a single number, that is only up to 10 digits, it is even easier:
^\s[0-9]{1,10}\s$
The regex you're looking for is this:
/(?=^[-+]?\d*\.?\d+$)^.{1,10}$/
Keep in mind that this regex will allow maximum length of input to 10 which includes optional + or - sign at start and a decimal point ..
you can try this:
^(?<=\s)(\-?[\d]{1,10}(?=\s))$
This fails as it has 11 digits
Debug.WriteLine(Regex.IsMatch("12345678901", #"^\d{1,10}$").ToString());
Posted the above answer before you clarified you want up to 10 set of numbers delimited by space.
Tested the accepted answer and in .NET Regex it fails for me.
Even fixing the syntax error it still does not parse by space
Give this a try
Debug.WriteLine(Regex.IsMatch(" 12345 678901 12 ", #"^\s*([+-]?\d+)(\s+[+-]?\d+){1,9}\s*$").ToString());

telephone number regex

I am currently trying to validate UK telephone numbers:
The format I'm looking for is: 01234 567891 or 01234567891 - So I need the number to have 5 numbers then a space then 6 numbers or simply a 11 numbers.
The number must start with a 0.
I've had a look at a couple of examples:
/^[0-9]{10,11} - to check that the chars are all numbers
/^0[0-9]{9,10}$/ - to check that the first number is a 0
I'm just unsure how to put all these together and check if there is a space or not.
Could someone help me with this regex?
Thanks
Try this regex:
/^0\d{4}\s?\d{6}$/
Many people try to do input validation and formatting in a single step.
It is better to separate these processes.
Match UK telephone number in any format
^(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?$
The above pattern allows the user to enter the number in any format they are comfortable with. Don't constrain the user into entering specific formats.
Extract NSN, prefix and extension
^(\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)(44)\)?[\s-]?)?\(?0?(?:\)[\s-]?)?([1-9]\d{1,4}\)?[\d[\s-]]+)((?:x|ext\.?|\#)\d{3,4})?$
Next, extract the various elements.
$2 will be '44' if international format was used, otherwise assume national format with leading '0'.
$4 contains the extension number if present.
$3 contains the NSN part.
Validation and formatting
Use further RegEx patterns to check the NSN has the right number of digits for this number range. Finally, store the number in E.164 format or display it in E.123 format.
There's a very detailed list of validation and display formatting RegEx patterns for UK numbers at:
http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_UK_Telephone_Numbers
It's too long to reproduce here and it would be difficult to maintain multiple copies of this document.
If you are looking for all UK numbers, I'd look for a bit more than just that number, some are in the format 020 7123 4567 etc.
^\s*\(?(020[7,8]{1}\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3}\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$
/\d*(*)*+*-*/
Simple Telephone Regex includes + () and - anywhere, as well as digits
I think ^0[\d]{4}\s?[\d]{5,6}} will work for you. I have used [\d] instead of [0-9].
I find that RegExr is a useful online tool to check and try your regular expressions. It also has a nice library of examples to help point you in the right direction
you should just count the number of digits and check that it's 10,
Some UK numbers have only 9 digits, not 10 (not including the leading 0).
These include 40 of the 01 area codes (using "4+5" format), the 016977 area code (using "5+4" format), all 0500 numbers and some 0800 numbers.
There's a list at: http://www.aa-asterisk.org.uk/index.php/01_numbers
This US numbers pattern accepts following phones as well:
800-432-4500, Opt: 9, Ext: 100316
800-432-4500, Opt: 9, Ext: X100316
800-432-4500, Option #3
(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4}),?(?:\s*(?:#|x\.?|opt(\.|:|\.:)?|option)\s*#?(\d+))?,?(?:\s*(?:#|x\.?|ext(\.|:|\.:)?|extension)\s*(\d+))?
(used this answer in other topic as start point)