Asp.net (C #) code that limits user input of specified characters and numbers
Source: Internet
Author: User
Here is Code :
Only user names can be entered: the user name must start with 0 ~ 9. ~ Z or ~ Z!
Copy code The Code is as follows: protected void button3_click (Object sender, eventargs E)
{
Int error_count = 0; // used to identify the validity of a user name
String STR = textbox1.text. Trim ();
If (STR = string. Empty)
{
Response. Write ("the user name cannot be blank! ");
Return;
}
STR = Str. substring (0, 1); // the user name contains 1st characters
String strchar = ", A, B, C, D, E, F, G, H, I, J, K, L, M, n, O, P, Q, R, S, T, U, V, W, X, Y, Z, A, B, C, D, E, F, G, h, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z ";
String [] vcarray = strchar. Split (',');
For (INT I = 0; I <vcarray. length; I ++)
{
If (STR! = Vcarray [I])
{
Error_count ++;
}
Else
{
Error_count = 0; // if the user name is valid, initialize the variable error_count to 0,
Break;
}
}
If (error_count> 0) // If the variable error_count is greater than 0, the user name is invalid.
{
Response. Write ("<SCRIPT> alert ('user name must start with 0 ~ 9. ~ Z or ~ Z! ') </SCRIPT> ");
}
Else
{
Response. Write ("<SCRIPT> alert ('legal user name, available! ') </SCRIPT> ");
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service