I need to find a reg ex that only allows alphanumeric. So far, everyone I try only works if the string is alphanumeric, meaning contains both a letter and a number. I just want one what would allow either and not require both.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
or, if you want a minimum of one character:
Square brackets indicate a set of characters. ^ is start of input. $ is end of input (or newline, depending on your options). \s is whitespace.
The whitespace before and after is optional.
The parentheses are the grouping operator to allow you to extract the information you want.
EDIT: removed my erroneous use of the \w character set.
Instead of checking for a valid alphanumeric string, you can achieve this indirectly by checking the string for any invalid characters. Do so by checking for anything that matches the complement of the valid alphanumeric string.
Here is an example:
Notice the logical not operator at
isValid
, since I'm testing whether the string is false, not whether it's valid.Use the word character class. The following is equivalent to a
^[a-zA-Z0-9_]+$
:Explanation:
Use
/[^\w]|_/g
if you don't want to match the underscore.This will work
It accept only alphanumeriuc characters alone:
test cases pased :
or
You can also try this one. this expression satisfied at least one number and one character and no other special characters
in angular can test like:
PLUNKER DEMO
Refered:Regular expression for alphanumeric in Angularjs
Try this... Replace you field ID with #name... a-z(a to z), A-Z(A to Z), 0-9(0 to 9)