简体   繁体   English

正则表达式允许3个数字,没有特殊字符和空格

[英]Regex allowing 3 numbers with no special characters and space

I am using a regex as /^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?$/ which allow only 3 numbers and no special characters 我使用正则表达式作为/ ^-?(?:\\ d + | \\ d {1,3}(?:,\\ d {3})+)?$ /,它只允许3个数字且没有特殊字符

I need to include space check as well. 我还需要包括空间检查。 Please help me 请帮我

I don't know why your regular expression is so complex. 我不知道为什么您的正则表达式如此复杂。 If you need three digits with no other characters, just use this: 如果您需要三位数字且没有其他字符,请使用以下命令:

/^[0-9]{3}$/

That will only validate strings that are three digits with nothing else, "324", "857", "111". 那只会验证三位数的字符串,别无其他,“ 324”,“ 857”,“ 111”。 You get it. 你懂了。

If you have other requirements, please update your question with them. 如果您还有其他要求,请与他们一起更新您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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