如何验证一个文本框,只允许使用常规的前pression字母和数字? [英] How do I validate a text box to only allow letters and numbers using a regular expression?
问题描述
我想验证一个文本框,不使用常规的前pressions接受任何特殊字符。它只是需要的字母和数字从0到9,请为我提供正确的正则表达式。
I want to validate a text box that doesn't accept any special characters using regular expressions. It just takes letters and numbers from 0 to 9. Please provide me the correct regex.
推荐答案
一个普通的前pression将 [A-ZA-Z0-9] *
的一个箱子可能是空或 [A-ZA-Z0-9] +
的盒子,必须在其中至少有一个字符。如果你有一个最小和最大长度,你可以做更多的东西一样 [A-ZA-Z0-9] {M,N}
,其中M是最小长度和n是最大长度,如果你只有一个最小长度,正则表达式看起来更像 [A-ZA-Z0-9] {男,}
,其中M是最小字符数。
A regular expression would be [a-zA-Z0-9]*
for a box that could be empty or [a-zA-Z0-9]+
for a box that must have at least one character in it. If you have a minimum and maximum length, you can do something more like [a-zA-Z0-9]{m,n}
where m is the minimum length and n is the maximum length and if you only had a minimum length, the regex would look more like [a-zA-Z0-9]{m,}
where m was the minimum number of characters.
有关详细信息,您可能需要阅读在ASP 普通防爆pressions这个MSDN文章.NET 。
For more information, you might want to read this MSDN article on Regular Expressions in ASP.NET.
这篇关于如何验证一个文本框,只允许使用常规的前pression字母和数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!