简体   繁体   English

Alpha数字的正则表达式,没有空格和9个字符的输入?

[英]regular expression for Alpha numeric,no spaces and 9 character input?

I have used 我用过

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

for alphanumeric no spaces its working 对于字母数字没有空格,它的工作原理

now i have to limit only 9 character are allowed not more not less only 9 现在我必须限制只允许9个字符,不能少于9个字符

You can use curly braces to set limits on repetition: 您可以使用花括号来设置重复次数限制:

"^[a-zA-Z0-9]{9}$" 

That will only match strings in which the pattern in the character class is repeated exactly 9 times. 这只会匹配字符类中的模式精确重复9次的字符串。

Note that you can also use this to limit repetition to a range. 请注意,您也可以使用此选项将重复次数限制为一个范围。 This example would only match strings in which the character class pattern is repeated between 3 and 5 times: 此示例仅匹配字符类别模式重复3到5次的字符串:

"^[a-zA-Z0-9]{3,5}$"

And you can leave out the second number but keep the comma to specify a minimum number of repetitions, so this one will match "at least 5": 并且您可以省略第二个数字,但保留逗号以指定最小重复次数,因此该数字将匹配“至少5个”:

"^[a-zA-Z0-9]{5,}$"

The simplest way is to use Range Validator with your regular expression validator. 最简单的方法是将范围验证器与正则表达式验证器一起使用。 or go with James Allardice solution, it may also help you. 或者使用James Allardice解决方案,它也可能对您有所帮助。 but I will suggest to use Range Validator as well with your Regular Expression click 但我建议您在正则表达式点击中同时使用范围验证器

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

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