[英]Regular expression to validate textbox length
I want a regular expression to validate an ASP textbox field with the minimum length of 11 characters and in the middle of the string should be a "-" sign. 我想要一个正则表达式来验证ASP文本框字段,该字段的最小长度为11个字符,并且在字符串的中间应为“-”符号。 The sample string is: "0000-011111". 示例字符串是:“ 0000-011111”。 I want to validate the textbox to make sure user enters a minimum of 10 numbers with "-" sign after 4 digits using regular expressions. 我想验证文本框,以确保用户使用正则表达式在4位数字之后输入至少10个带“-”符号的数字。 Please help me. 请帮我。
Thank you. 谢谢。
Use 采用
\d{4}-\d{6}
\\d
represents a digit, -
is a literal dash and the number in the curly brackets force the preceeding token to be present the given number of times. \\d
代表一个数字, -
是文字破折号,大括号中的数字强制前面的令牌出现给定的次数。
^\d{4}-\d{6,}$
You should use also ^
at the beginning and $
at the end to ensure that there is nothing before and after your string that you don't want to have. 您还应该在开头使用^
,在结尾使用$
,以确保您不需要的字符串前后没有任何内容。 Also important is the {6,}
so it will match at least 6 digits, without ,
it will match exactly 6 digits. {6,}
也很重要{6,}
因此它将至少匹配6位数字,如果没有,
它将精确匹配6位数字。 If you want set a maximum of digits you can specify after the ,
, eg {6,20}
. 如果你想设置最大的数字可以指定后,
如{6,20}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.