AngularJS alpha only regex is accepting special characters [duplicate] - javascript

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}$

Related

How to define a range from -50 to 50 using regular expression [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
javascript regex optional minus
(1 answer)
Closed 2 years ago.
my question is, how to define a regular expression, if a range is between -50 to 50.
I have used this regular expression:
'\\b(-?[1-9]|-?[1-4][0-9]|-?50|[0-9])\\b'
but it can only check from 0 to 50
Why I use this pattern, because I use this pattern for input field such like this:
<inpit [pattern]="regex">
this pattern can only accept regex string
any solutions??

Input should allow alphabets, special characters but not number values [duplicate]

This question already has answers here:
numbers not allowed (0-9) - Regex Expression in javascript
(6 answers)
Closed 2 years ago.
I am trying to create a react(javascript) form, In that one field should allow all values (Uppercase letters, Lowercase letters and special characters) but not numbers.
Is there any regex or any other solution?
Thanks in advance.
You can simply check that a string DOESN'T contain numbers using regex \d which matches all numbers:
!(/\d/.test(string))

Regex for allowing Numeric, alphabet, hyphen(-) space and apostrophes(') [duplicate]

This question already has answers here:
REGEX - Allow Numbers and . - /
(7 answers)
Closed 2 years ago.
Currently I have a textbox that accepts only Alphabet, hyphens(-), space and apostrophes('). Now I would like to add numeric values as well to it. Currently I am using the Regex as below:
/^[a-zA-ZÀ-ÖØ-öø-ÿ' -]+$/
How would I achieve adding numerics as well to the above?
To allow numbers, simply add 0-9 in your regex, like so:
/^[0-9a-zA-ZÀ-ÖØ-öø-ÿ' -]+$/

regex to match any 1+ non-blankspace character [duplicate]

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
Using explicitly numbered repetition instead of question mark, star and plus
(4 answers)
Match exact string
(3 answers)
Closed 4 years ago.
I need to have a Regex for matching a single (or greater) non- blank space character (would allow all special characters such as !,' etc...). Would
var filter = /\S+/;
be sufficient? This seems to work for 1 or greater.
Would:
var filter = /\S+/{3,};
be sufficient for 3 or more of the non-same characters (like "def", "a!c", "dA!!f", but not "some bird"?

I need REGEXP for alpha Numeric zip code, which contains minimum 3 & maximum 10 values [duplicate]

This question already has answers here:
JavaScript regex for alphanumeric string with length of 3-5 chars
(3 answers)
Closed 7 years ago.
I need REGEXP for alpha Numeric zip code, which contains minimum 3 & maximum 10 values.
Invalid inputs are: AAAAA, A1, AA, 12, 2A
Valid inputs are: 123456, 123, A1234, A12, A12A, A9A
This is the regex I'm currently using:
/(^[A-z0-9]\d{3,10})+$/
It doesn't allow to specify only digits like this 12345 but input like A123 matches correctly.
The question is not completely clear. If you mean that you can use between 3 and 10 characters, and these characters can be alphanumerical characters (digits and [A-Za-z]), you can use:
/^(?=.*\d.*)[A-Za-z0-9]{3,10}$/
regex101 demo.
The regex works as follows:
^[A-Za-z0-9]{3,10}$ says the regex consists out of 3 to 10 characters that can be digits and/or A-Z/a-z.
The lookahead (?=.*\d.*) enfoces that the string contains at least one digit somewhere in the string.

Categories