简体   繁体   中英

Regular expression for only alphabet and number but not space

I have a input text box in angular js which need to accept only alphabets and numbers but not special character as well as spaces.

For that I am using "^[a-zA-Z0-9]+$" but its not working as i am expecting.

$error is only for special symbol but not for spaces. what i am doing wrong here please help.

I have read some people has used " " in Regex but its to allow space.

Give a shot to this :

^[a-zA-Z0-9_]*$

It's Tested .

Go To Link to test again : Regex Tested

Try this i hope it will work :

Pattern : /([A-Za-z0-9]+)/

working example : http://regexr.com/3ecr5

If you want to match all occurrences in the string then you can use global search by defining g flag.

Pattern : /([A-Za-z0-9]+)/g

Working example : http://regexr.com/3ecr8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM