& lt div>< ASP: regular expression validator id = "regular expression validator1"validation expression = "[0-9] {4,8}" runat = "server" errormessage = "Enter a number with a length of (4-8) digits!" display = " Dynamic " ControlToValidate = " textbox 1 " >& lt/ASP:regular expression validator & gt; & lt/div & gt;
Controltovalidate = "textbox1"indicates the ID of the text box to be controlled, and validationexpression = "[0-9] {4,8}" indicates that 4-8 digits can be entered. In addition, other contents can be specified, such as: verification expression = "[a-za-z0-9] {6, 18} "means that English letters or numbers with a length of (4 ~ 8) bits can be entered. Are all "regular expressions". You can search online if you are interested.
Then you can introduce the following:
Use the system. Text. Regular expression;
Public static bool Validate(string regexString, string validateString)
{
Regex Regex = new Regex(Regex string);
Returns a regular expression. IsMatch(validateString。 trim());
}
Bohr numone = validate ("[0-9] * $", textbox1.text);
Limit input number: [0-9] * $
Restrict the input of n digits: \ d {n} $
Enter at least n numbers: \ d {n,} $
Limit the input of m-n digits: \ d {m, n} $
Limit the input of zero and non-zero numbers: (0 | [1-9] [0-9] *) $
Restrict the input of positive real numbers with two decimal places: [0-9]+ (. [0-9] {2})? $
The input of positive real numbers with 1-3 decimal places is restricted: [0-9]+ (. [0-9] { 1,3})? $
Restrict the input of non-zero positive integers: \+? [ 1-9][0-9]*$
Restrict the input of nonzero negative integers: \-[ 1-9] [0-9] * $
Restrict input of non-negative integer (positive integer +0) \ d+$
Restrict the input of non-positive integer (negative integer+0) (-\ d+) | (0+) $
Restrict the input of characters of length 3:. {3} $
You can also limit the following types:
Integer:-? \d+$
Non-negative floating point number (positive floating point number +0): \ d+(\. \ d+)? $
Positive floating point number (([0-9]+\. [0-9] * [ 1-9] [0-9] *) | ([0-9] * [ 1-9] * \.[0-9]
Non-positive floating-point number (negative floating-point number+0) (-\ d+(\). \ d+))? )|(0+(\.0+)? ))$
Negative floating point number (-([0-9]+\. [0-9] * [ 1-9] [0-9] *) | ([0-9] * [ 1-9] * \.]
Floating point number (-? \d+)(\。 \d+)? $