[英]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. 我在angular js中有一个输入文本框,该文本框只需要接受字母和数字,而不能接受特殊字符和空格。
For that I am using "^[a-zA-Z0-9]+$"
but its not working as i am expecting. 为此,我正在使用
"^[a-zA-Z0-9]+$"
但它没有按我期望的那样工作。
$error is only for special symbol but not for spaces. $ error仅用于特殊符号,不适用于空格。 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]+)/
模式:
/([A-Za-z0-9]+)/
working example : http://regexr.com/3ecr5 工作示例: http : //regexr.com/3ecr5
If you want to match all occurrences in the string then you can use global search by defining g
flag. 如果要匹配字符串中所有出现的内容,则可以通过定义
g
标志来使用全局搜索。
Pattern : /([A-Za-z0-9]+)/g
模式:
/([A-Za-z0-9]+)/g
Working example : http://regexr.com/3ecr8 工作示例: http : //regexr.com/3ecr8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.