简体   繁体   English

仅字母和数字但不包含空格的正则表达式

[英]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.

相关问题 具有第一个字母,至少一个字母和一个数字的字母数字的正则表达式 - Regular Expression for alphanumeric with first alphabet and at least one alphabet and one number 澳大利亚移动电话号码正则表达式验证需要在号码之间留出空格 - Australian Mobile number regular expression validation needs to allow space in between number 名称的正则表达式,只接受字母,两个单词之间只接受空格。 名称的开头或结尾不允许有空格 - Regular expression for name which accepts alphabets only and space only between two words. no space allowed at the start or at end of the name 用于数字和逗号的 AngularJS 正则表达式 - AngularJS regular expression for number and comma 实数的 ng-pattern 正则表达式 - ng-pattern regular expression for real number AngularJS正则表达式限制字符数问题 - Angularjs regular expression to restrict number of characters issue 仅允许单词和空格的正则表达式 - regular expression for allowing words and spaces only 仅数字自定义指令不调用空格键 - Number only Custom directive not calling on space key 正则表达式匹配字符串中任意位置的一定数量的数字 - Regular expression to match a certain number of digits anywhere in a string 如何在angularjs中做国家保险号码正则表达式 - How to do national insurance number regular expression in angularjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM