1. Use verification controls
This is a client verification. Microsoft developers encapsulate the most common verification functions, which significantly improves the development efficiency and is especially flexible in custom verification controls, we can design the verification logic on our own. However, the verification control received browser restrictions. Remember to use the FireFox browser to browse during a development process and find that all the verification controls failed. This is not ASP.. NET vulnerabilities can only be said that the browser standards are not unique.
ASP. NET has six public verification controls:
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
2. Verify with JS
JS verification, which appeared earlier, also belongs to client verification. Its flexible and applicable performance is favored by people.
3. Background Program Verification
Despite the flexibility of client-side verification, the limitations are also obvious, and server-side verification is essential.
(1) Security: If a malicious attacker deletes all the verification controls and JS verification on the client page, and the server does not perform effective verification, it will certainly cause a large number of vulnerabilities to the attacker, the consequences are unimaginable.
(2) Client verification limitations, such as user registration, need to determine whether the user name exists, this needs to be determined from the database query.
(3) various powerful verification functions can be implemented here.
Disadvantage: increased server load
4. Ajax Verification
This is a combination of client verification and server verification. Because the ajax framework is used, the performance cost is small, but the user experience and encoding simplicity are improved.
In the verification process, the validation of different formats requires powerful and flexible regular expressions.
Use a regular expression for verification:
When writing a program or webpage that processes strings, it is often necessary to find strings that meet certain complex rules. Regular Expressions are tools used to describe these rules. In other words, a regular expression is the code that records text rules.
For more information about regular expressions, see: http://www.regexlab.com/zh/regref.htm.
Regular expressions are used for string processing, form verification, and other occasions. They are very practical and efficient, so they are widely used. Below I will use several examples to illustrate the specific application of regular expressions in verification.
Here I will introduce the format of the verification phone number.
<1> verify with JSCopy codeThe Code is as follows: <asp: Button ID = "Button2" runat = "server" Text = "test" OnClientClick = "return checkCellPhone ();" OnClick = "Button2_Click"/>
Verify the JS Code of the mobile phoneCopy codeThe Code is as follows: <script type = "text/javascript">
Function checkCellPhone () // verify the mobile phone number
{
Var mobile = document. getElementById ("tbMobile"). value;
If (mobile! = "")
{
Var reg0 =/^ 13 \ d {5, 9} $/; // 130--139. At least 7 characters
Var reg1 =/^ 153 \ d {153} $/; // China Unicom. At least 7 characters
Var reg2 =/^ 159 \ d {159} $/; // move. At least 7 characters
Var reg3 =/^ 158 \ d {158} $/; // move. At least 7 characters
If (reg0.test (mobile) | reg1.test (mobile) | reg2.test (mobile) | reg3.test (mobile ))
{
Return true;
}
Else
{
Alert ("Mobile Phone Number Format error! ");
Document. getElementById ("tbMobile"). focus ();
Return false;
}
}
Else
{
Alert ("the mobile phone number cannot be blank! ");
Document. getElementById ("tbMobile"). focus ();
Return false;
}
}
</Script>