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

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"))

Related

Regular Expressions Vue [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 21 hours ago.
The community is reviewing whether to reopen this question as of 10 hours ago.
Improve this question
I'm trying to validate an input with regEx in Vue, which I don't have any idea how to make one and couldn't find online how to match what I want to do.
The thing is I'm trying to validate a price that should be a float with 2 decimal numbers, and it can be 1 number before the . or 9 digits. For example:
0.50
1.00
99999.99
999999999.00
I tried this:
v => (/\d{1,3}(?:[.,]\d{3})*(?:[.,]\d{2})/.test(v))
But doesn't work.
Sorry if my english is not very good. I appreciate the help!
To match 1-9 digits before the dot, and 2 decimal numbers:
^\d{1,9}\.\d{1,2}$
See a regex101 demo.
What do you want? Check the value for matching a number from 0 to 999999999 in the integer part and no more than 2 numbers after "."?
A template assuming that the entire string being checked from the beginning (^) to the end ($) consists of
mandatory initial part, which is either 0 or contains from 1 to 9 digits, and does not start with "0" ;
optional ending of "." and two digits:
^([1-9]\d{0,8}|0)(.\d{1,2})?$

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

Singapore Mobile Number RegEx [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 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));

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
‐ First digit can be 1-9
‐ Second digit can only be 0 or 5
If user enters 3 digits
‐ First digit can only be a 1
‐ 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

AngularJS alpha only regex is accepting special characters [duplicate]

This question already has answers here:
I want to ignore square brackets when using javascript regex [duplicate]
(4 answers)
Closed 8 years ago.
I have a very simple form with this regex pattern set on my first/last name fields ng-pattern="/^[a-zA-z]{2,30}$/" and both fields accept this value as being valid e.g. Tester\^*&^%. The first/last name should only accept alpha character a-zA-Z with a minimum of 2 characters and a max of 30.
Here is the wrong thing.
^[a-zA-z]{2,30}$
^
|
It would match \^ symbols because these symbols are comes under the range from A to z.
Modified regex.
^[a-zA-Z]{2,30}$

Categories