Guidance:
Source: http://www.chinaitbbs.com.cn/topic-1745.aspx
Widget name Function Description
Requiredfieldvalidator (field verification required) is used to check whether input values exist.
Comparevalidator (comparison verification) compares two inputs according to Settings
Rangevalidator (range verification) whether the input is in the specified range
Regularexpressionvalidator (Regular Expression verification) Regular Expression verification control
Custom verification control
Validationsummary (Verification summary) summarizes verification results
Usage:
I. Use of requiredfieldvalidator (field verification is required)
The standard code used by the requiredfieldvalidator control is as follows:
<Asp: requiredfieldvalidator id = "validator_name" runat = "server"
C
Errormessage = "error message"
Display = "static | dymatic | none">
Placeholder
</ASP: requiredfieldvalidator>
In the above Code:
Controltovalidate: indicates the ID of the control to be checked;
Errormessage: indicates the error message when the check is invalid;
Display: Display Mode of the error message. Static indicates that the error message of the control occupies a certain position on the page. dymatic indicates that the page control is occupied only when the control error message appears; none indicates that the error is not displayed when it appears, but it can be displayed in validatorsummary;
Placeholder: indicates that when the display is static, the error information occupies the page space as large as the "Placeholder ".
Instance:
<Asp: textbox id = "txtname" runat = "server"/>
<Asp: requiredfieldvalidator id = "validator1" runat = "server"
C
Errormessage = "name required"
Display = "static">
* Name is required
</ASP: requiredfieldvalidator>
2. comparevalidator Control
Compare whether the input of the two controls meets the program settings
The attributes are basically the same as those of requiredfieldvalidator.
3. rangevalidator Control
Verify that the input is in a certain range and the range is determined by maximumvalue (maximum) and minimunvlaue. The standard code is as follows:
<Asp: rangevalidator id = "vaidator_id" runat = "server"
C
Type = "integer"
Minimumvalue = "minimum"
Maximumvalue = "maximum"
Errormessage = "error message"
Display = "static | dymatic | none">
Placeholder
</ASP: rangevalidator>
In the above Code:
Use minimumvalue and maximumvalue to define the input value range of the control, and use type to define the type of the input value of the control.
4. regularexpresionvalidator (Regular Expression) Control
Regular Expression verification controls are very powerful. You can easily construct verification methods by yourself. Let's take a look at the Standard Code:
<Asp: regularexpressionvalidator id = "validator_id" runat = "server"
C
Validati
Errormessage = "error message"
Display = "static">
Placeholder
</ASP: regularexpressionvalidator>
In the above standard code, validationexpression is the focus. Let's take a look at its structure:
In validationexpression, different characters indicate different meanings:
"." Indicates any character;
"*" Indicates that it is easy to combine with other expressions;
"[A-Z]" represents any capital letter;
"/D" indicates a number;
Note that quotation marks are not included in the preceding expressions;
Example:
Regular Expression: ". * [A-Z]" indicates a combination of any character starting with a number followed by an uppercase letter.
Regular Expression description
The first four types are commonly used.
In the field checkrule in the sr_sourceitem table, record the verification control that this field should use (named by the name of each verification control), and store the prompt message during verification in the checkmsg field,
Store default values in the defaultvalue Field
In the program
If (checkrule! = "")
{
Switch (Control name)
{
Case ("system. Web. UI. webcontrols. requiredfieldvalidator "):
// Create the requiredfieldvalidator control;
Break;
Case ("system. Web. UI. webcontrols. dropdownlist "):
......
Break;
}
// Create a control by name
}
Appendix:
All symbolic interpretations
Character Description
/Mark the next character as a special character, an original character, or a backward reference, or an octal escape character. For example, 'n' matches the character "N ". '/N' matches a line break. The sequence '//' matches "/" and "/(" matches "(".
^ Matches the start position of the input string. If the multiline attribute of the Regexp object is set, ^ matches the position after '/N' or'/R.
$ Matches the end position of the input string. If the multiline attribute of the Regexp object is set, $ also matches the location before '/N' or'/R.
* Matches the previous subexpression zero or multiple times. For example, Zo * can match "Z" and "Zoo ". * Is equivalent to {0 ,}.
+ Match the previous subexpression once or multiple times. For example, 'Zo + 'can match "zo" and "Zoo", but cannot match "Z ". + Is equivalent to {1 ,}.
Match the previous subexpression zero or once. For example, "Do (ES )? "Can match" do "in" do "or" does ".? It is equivalent to {0, 1 }.
{N} n is a non-negative integer. Match n times. For example, 'O {2} 'cannot match 'O' in "Bob", but can match two o in "food.
{N,} n is a non-negative integer. Match at least N times. For example, 'O {2,} 'cannot match 'O' in "Bob", but can match all o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O {0,} 'is equivalent to 'o *'.
Both {n, m} m and n are non-negative integers, where n <= m. Match at least N times and at most m times. For example, "O {1, 3}" matches the first three o in "fooooood. 'O {0, 1} 'is equivalent to 'o? '. Note that there must be no space between a comma and two numbers.
When this character is followed by any other delimiter (*, + ,?, The matching mode after {n}, {n ,}, {n, m}) is not greedy. The non-Greedy mode matches as few searched strings as possible, while the default greedy mode matches as many searched strings as possible. For example, for strings "oooo", 'O ++? 'Will match a single "O", and 'O +' will match all 'O '.
. Match any single character except "/N. To match any character including '/N', use a pattern like' [./N.
(Pattern) matches pattern and obtains this match. The obtained match can be obtained from the generated matches set. The submatches set is used in VBScript, and $0… is used in JScript... $9 attribute. To match the parentheses, use '/(' or '/)'.
(? : Pattern) matches pattern but does not get the matching result. That is to say, this is a non-get match and is not stored for future use. This is useful when you use the "or" character (|) to combine each part of a pattern. For example, 'industr (? : Y | ies) is a simpler expression than 'industry | industries.
(? = Pattern) Forward pre-query: matches the search string at the beginning of any string that matches pattern. This is a non-get match, that is, the match does not need to be obtained for future use. For example, 'windows (? = 95 | 98 | nt | 2000) 'can match "Windows" in "Windows 2000", but cannot match "Windows" in "Windows 3.1 ". Pre-query does not consume characters, that is, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters.
(?! Pattern) negative pre-query: matches the search string at the beginning of any string that does not match pattern. This is a non-get match, that is, the match does not need to be obtained for future use. For example, 'windows (?! 95 | 98 | nt | 2000) 'can match "Windows" in "Windows 3.1", but cannot match "Windows" in "Windows 2000 ". Pre-query does not consume characters. That is to say, after a match occurs, the next matching search starts immediately after the last match, instead of starting after the pre-query characters.
X | y matches X or Y. For example, 'z | food' can match "Z" or "food ". '(Z | f) Ood' matches "zood" or "food ".
[Xyz] Character Set combination. Match any character in it. For example, '[ABC]' can match 'A' in "plain '.
[^ XYZ] combination of negative character sets. Match any character not included. For example, '[^ ABC]' can match 'p' in "plain '.
[A-Z] character range. Matches any character in the specified range. For example, '[A-Z]' can match any lowercase letter in the range of 'A' to 'Z.
[^ A-Z] negative character range. Matches any character that is not within the specified range. For example, '[^ A-Z]' can match any character that is not in the range of 'A' to 'Z.
/B matches a word boundary, that is, the position between a word and a space. For example, 'er/B 'can match 'er' in "never", but cannot match 'er 'in "verb '.
/B matches non-word boundaries. 'Er/B 'can match 'er' in "verb", but cannot match 'er 'in "never '.
/CX matches the control characters specified by X. For example,/cm matches a control-M or carriage return character. The value of X must be either a A-Z or a-Z. Otherwise, C is treated as an original 'C' character.
/D matches a numeric character. It is equivalent to [0-9].
/D matches a non-numeric character. It is equivalent to [^ 0-9].
/F matches a break. It is equivalent to/x0c and/Cl.
/N matches a linefeed. It is equivalent to/x0a and/CJ.
/R matches a carriage return. It is equivalent to/x0d and/cm.
/S matches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [/f/n/R/T/V].
/S matches any non-blank characters. It is equivalent to [^/f/n/R/T/V].
/T matches a tab. It is equivalent to/x09 and/CI.
/V matches a vertical tab. It is equivalent to/x0b and/ck.
/W matches any word characters that contain underscores. It is equivalent to '[A-Za-z0-9 _]'.
/W matches any non-word characters. It is equivalent to '[^ A-Za-z0-9 _]'.
/XN matches n, where N is the hexadecimal escape value. The hexadecimal escape value must be determined by the length of two numbers. For example, '/x41' matches "". '/X041' is equivalent to '/x04' & "1 ". The regular expression can use ASCII encoding ..
/Num matches num, where num is a positive integer. References to the obtained matching. For example, '(.)/1' matches two consecutive identical characters.
/N identifies an octal escape value or a backward reference. If there are at least N obtained subexpressions before/N, then n is a backward reference. Otherwise, if n is an octal digit (0-7), n is an octal escape value.
/Nm identifies an octal escape value or a backward reference. If at least one child expression is obtained before/nm, the NM is backward referenced. If at least N records are obtained before/nm, n is a backward reference followed by text M. If none of the preceding conditions are met, if n and m are Octal numbers (0-7),/nm matches the octal escape value nm.
/NML if n is an octal digit (0-3) and M and l are octal digits (0-7), the octal escape value NML is matched.
/UN matches n, where n is a Unicode character represented by four hexadecimal numbers. For example,/u00a9 matches the copyright symbol (?).
Usage in VBScript:
Function gfcheck (OBJ)
Dim strcheck' pending string
Dim objre 'regular expression object
Dim strrtn' Regular Expression judgment result
Strcheck = obj. Value
Set objre = new Regexp
Objre. pattern = "^ [A-Za-z0-9] {13} $" '13-bit English character and number string
Gfcheck = objre. Test (strcheck) 'returns true if it conforms to the regular expression, and false if it does not.
Set objre = nothing
End Function
Common Regular Expressions
1. non-negative integer: "^/d + $"
2. Positive Integer: "^ [0-9] * [1-9] [0-9] * $"
3. Non-positive integer: "^ (-/d +) | (0 +) $"
4. negative integer: "^-[0-9] * [1-9] [0-9] * $"
5. Integer: "^ -? /D + $"
6. Non-negative floating point number: "^/d + (/./d + )? $"
7. Positive floating point: "^ (0-9) + /. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] */. [0-9] +) | ([0-9] * [1-9] [0-9] *) $"
8. Non-Positive floating point: "^ (-/d +/./d + )?) | (0 + (/. 0 + )?)) $"
9. Negative floating point: "^ (-(Regular regular expression of Positive floating point number) $"
10. English string: "^ [A-Za-Z] + $"
11. English capital string: "^ [A-Z] + $"
12. lowercase English string: "^ [A-Z] + $"
13. English character numeric string: "^ [A-Za-z0-9] + $"
14. English numbers and underline strings: "^/W + $"
15. Email Address: "^ [/W-] + (/. [/W-] +) * @ [/W-] + (/. [/W-] +) + $"
16. url: "^ [A-Za-Z] +: // (/W + (-/W + )*)(/. (/W + (-/W + )*))*(/? /S *)? $"
This article is transferred from
Http://hi.baidu.com/tonyfirst1/blog/item/d7e1cab47a9dd6728ad4b26a.html