Singapore Mobile Number RegEx [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
The Phone Number Should Start with +65, Followed By 6|8|9 with Total of 11 Digits For Ex : +6598798765
Thank You

/\+65(6|8|9)\d{7}/g
\+ matches the character + literally (case sensitive)
65 matches the characters 65 literally (case sensitive)
1st Capturing Group (6|8|9)
1st Alternative 6 (6 matches the character 6 literally (case sensitive))
2nd Alternative 8 (8 matches the character 8 literally (case sensitive))
3rd Alternative 9 (9 matches the character 9 literally (case sensitive))
\d{7} matches a digit (equal to [0-9])
{7} Quantifier — Matches exactly 7 times

You should use the cap(^) to indicate start of a string and EOS($) to specify the end of string.
var re=/^\+65(6|8|9)\d{7}$/;
var true_mob = "+6561234567";
var false_mob = "+6512345678";
console.log(re.test(true_mob));
console.log(re.test(false_mob));

Related

Regex to accept 7 to 10 digit number with dashes in between the number [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I would need help on regex for accepting any 7 digit to 10 digit number (no decimals) along with hyphen or spaces in between any where in the digit.
For example ,
Below are valid scenarios
0123456789
000-25-392-93
0-1-2-3-4-5-6-7-8-9
0 1-2 3-4 5-6 7
Could some be able provide the best regex to accept this ?
Try this regex:
^\d(?:[- ]*\d){6,9}$
^\d starting with a digit.
(?:[- ]*\d){6,9} followed by another digit with any amount of - or whitespaces inbetween, repeat 6 to 9 times, so 7 to 10 digits in total.
$ end of string.
See the test case
const texts = [
'0123456789',
'000-25-392-93',
'0-1-2-3-4-5-6-7-8-9',
'0 1-2 3-4 5-6 7'
];
const regex = /^\d(?:[- ]*\d){6,9}$/;
console.log(texts.map(text => regex.test(text)));
^(?:\d[- ]?){7,10}$ could also work.
\d for the digit.
[- ] for the character after the number
? for checking if there is one space or - after the last number
{7,10} checks if it is between 7 and 10
Try it out:
https://regex101.com/r/Yx7iQ8/1
Here is one way to do that.
const numbers = [
"0123456789",
"000-25-392-93",
"0-1-2-3-4-5-6-7-8-9",
"0 1-2 3-4 5-6 7",
"01234" , // not valid
"33300409383850", // not valid
"123abc456def78" // not valid
];
const valid = numbers.filter(num => {
// count numerical digits by stripping out any non numerical characters
//const len = num.replace(/\D/g, "").length; // removes non numerical digits
const len = num.replace(/[\s\-]/g, "").length; // removes dashes and spaces
// now we will only accept elements where their digit count is between 7 and 10
return len > 6 && len < 11;
});
console.log(valid);

How to reject strange numbers and matching phone numbers in regular expression? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I've been thinking of using this regex for phone numbers: /(\+\d{1,3})?(\d{9,10})$/
and I want to exclude these weird number patterns, as example the following regular expressions:
longer repeat "123123123": /\b(\d+)\1+\b/
repeat number "111111111": ^(\d)\1+$
I tried with this but i dont have idea of how to combine with the phone number regular expression: ^(\d)(?!\1+$)\d*$
You can use a negative lookahead to exclude all lines matching your forbidden pattern.
^(?!(\d+)\1+$)(\+\d{1,3})?(\d{9,10})$
^ // start of line
(?! // negative lookahead
(\d+)\1+$ // matches repeating groups of numbers
)
(\+\d{1,3})? // optional area code
(\d{9,10}) // phone number
$ // end of line
https://regex101.com/r/gaA9UN/3
Note that single repeated digits are already covered by the repeating groups pattern, since a single digit is recognized as a group of length one.
Update
With the updated requirement to also disallow leading repeating groups followed by non-repeating numbers, here's an updated version:
^(?!(\d{2,})\1+)(?!(\d+)\2{3,})(\+\d{1,3})?(\d{9,10})$
^ // start of line
(?!(\d{3,})\1+) // disallow three or more leading repeating digits
(?!(\d+)\2{3,}) // disallow 1 or 2 leading digits from
// repeating 4 or more times
(\+\d{1,3})? // optional area code
(\d{9,10}) // phone number
$ // end of line
https://regex101.com/r/gaA9UN/4

javascript - mail exchange server string validation using regex [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
how can validate a mx server (similar to a domain) in the form of mx*.m**p.com by Regex? The first star can be any number without its length pre-defined 1, 11, 111, 1111, without leading 0s. The 2nd and 3rd stars are single letters in range of 0-9 and a-Z.
Examples:
mx1.m0bp.com
mx321.maBp.com
^mx[1-9][0-9]*\.m[0-9a-zA-Z]{2}p\.com$
^ indicates the start of the string
mx are the expected characters
[1-9] The number must not have a leading zero, so it must start with 1-9
[0-9]* Followed by zero or more other digits
\. The dot must be escaped as it has a special meaning
[0-9a-zA-Z]{2} Exactly two characters with the given range
p\.com again the next expected characters with another escaped dot
$ indicates the end of the string
Including the ^ and $ means you won't get a match from foomx1.m0bp.com or mx1.m0bp.comfoo
You can use the below regex to test the domain:
mx[0-9]+\.m[0-9a-zA-Z]{2}p\.com
console.log(/mx[0-9]+\.m[0-9a-zA-Z]{2}p\.com/gi.test("mx1.m0bp.com"))
console.log(/mx[0-9]+\.m[0-9a-zA-Z]{2}p\.com/gi.test("mx321.maBp.com"))

How to create a regular expression to accept only upto 12 digits? [duplicate]

This question already has answers here:
6 digits regular expression
(7 answers)
Closed 6 years ago.
How to create a regular expression to accept only upto 12 digits?
Many Thanks
/^\d{0,12}$/
... which breaks down as ...
/ # start regex
^ # anchor to start of string
\d # 0-9
{0,12} # 0-12 times
$ # anchor end of string
/ # end regex
(?:^|[^0-9])([0-9]{1,12})(?![0-9])
I have divided problem to 3 part according to answers.
Problem want to does not start with digit
(?:^|[^0-9]) means that starts with non digit character or does not start with any character
Problem want to consume 12 digit:
[0-9] means that we want to consume just digits
{1,12} means that we want to consume up to 12 character
Problem want to does not consume these 12 digit if 13rd character is digit also.
? means that look but does not consume
![0-9] means that this character could be everything except digit.

RegEx to match only multiples of 5 from 5 up to 150? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I don't know how to handle the conditions I have listed below.
I can do one scenario at a time, but not sure how to encompass all restrictions on one field:
Allows 1, 2 or 3 total digits in the field
If user enters only 1 digit
It can only be a 5
If user enters 2 digits
&dash; First digit can be 1-9
&dash; Second digit can only be 0 or 5
If user enters 3 digits
&dash; First digit can only be a 1
&dash; Second digit can be 0-5
• If second digit is 0-4, third digit can only be 0 or 5
• If second digit is a 5, third digit can only be 0
Furthermore, if possible:
Each scenario can be followed by the characters .00 or not(the .00 should be optional for entry)
Use the alternation | token and…
You can use the alternation token | in conjunction with beginning ^ and end $ of line tokens to capture 1-, 2-, or 3-digit matches.
You can then optionally match the .00 string with a non-capturing group (?:) and the optional ? token to match zero or one of that group.
Update:
/^5(?:\.00)?$|^[1-9][05](?:\.00)?$|^1[0-4][05](?:\.00)?$|^150(?:\.00)?$/gm
Commenter bobble bubble provided this more concise version.
/^(?:5|[1-9][05]|1[0-4][05]|150)(?:\.00)?$/gm
Source: Regexper.com

Categories