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. The sample string is: "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. 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{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. If you want set a maximum of digits you can specify after the ,
, eg {6,20}
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.