This article provides the asp tutorial. net user name verification (must be 0 ~ 9. ~ Z or ~ Z) Oh, only allow users to enter a username consisting of numbers and uppercase and lowercase letters.
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> ");
}
}