In ASP. for example, if the database is varchar (50), it is best to enter only 50 characters on the interface, this verification is required in some cases:
You can use the Length attribute for a single-line text box. This method is simple, but there is a problem that the Chinese character is only recorded as one character, and the database contains two characters, therefore, if the length is 50 and 50 characters are entered, the system reports an error. Therefore, length = 25 can be used to control the maximum possibility, this also reduces the number of characters in English characters. This is actually very important, as long as we increase the number of numbers that should be needed by a factor when designing the database.
The Length attribute of the multi-line text box does not work. Therefore, we need to use the following scheme:
<Script language = "JavaScript">
<! --
String. Prototype. Len = function (){
Return this. Replace (/[^ \ x00-\ xFF]/g, "**"). length;
}
Function checklength (source, arguments)
{
VaR validstrlength = 50;
If (arguments. value. Len () <= validstrlength)
Arguments. isvalid = true;
Else
Arguments. isvalid = false;
}
// -->
</SCRIPT>
Use the above script on the interface, and add the customvalidator verification control to verify the clientvalidationfunction attribute as "checklength". This method is the client function above, vaR validstrlength = 50; indicates the number of characters to be verified. It should be noted that the number of characters here will automatically distinguish between Chinese characters, and a Chinese character will be automatically recorded as two characters. Therefore, it is not required to be like a single-line text box, set it to half of the total number of characters.
Now, you can see the effect of the control through the above settings !!
Good luck!