When developing a web platform, you will always encounter some input judgments or restrictions on some special characters. Recently, I have been busy developing my own web platform (www.sanyalanhua.com, a self-developed web platform, as mentioned earlier). In the Membership registration system, I used JavaScript to make judgments on the browser .. For example, if you enter a password when registering a member, you must ignore other characters when specifying that the password can only contain numbers, letters, and uppercase/lowercase letters ..CodeIs
<Script language = "JavaScript">
Function fucpwdchk (STR)
{
VaR strsource = "0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ";
VaR ch;
VaR I;
VaR temp;
For (I = 0; I <= (Str. Length-1); I ++)
{
Ch = Str. charat (I );
Temp = strsource. indexof (CH );
If (temp =-1)
{
Return 0;
}
}
If (strsource. indexof (CH) =-1)
{
Return 0;
}
Else
{
Return 1;
}
}
Function checkreg ()
{If (! Fucpwdchk (document. adduser. cuspwd. Value )){
Alert ("prompt: only numbers and uppercase and lowercase letters can be used as passwords ");
Document. adduser. cuspwd. Focus ();
Return false;
}
}
</SCRIPT>
When we want to enter some contact information, such as the contact number, email address, and QQ, during the Member registration process, we have to filter out the input results when only numbers and email addresses are allowed for the contact phone number, which must comply with the mailbox format and QQ number, and only numbers are allowed... Javascript can be used directly on the browser side to determine whether or not .. The code is
<Script language = "JavaScript">
Function fucphochk (STR)
{
VaR strsource = "0123456789 ";
VaR ch;
VaR I;
VaR temp;
For (I = 0; I <= (Str. Length-1); I ++)
{
Ch = Str. charat (I );
Temp = strsource. indexof (CH );
If (temp =-1)
{
Return 0;
}
}
If (strsource. indexof (CH) =-1)
{
Return 0;
}
Else
{
Return 1;
}
}
Function checkreg ()
{
If (! Fucphochk (document. adduser. custel. Value )){
Alert ("Note: Only pure numbers can be used as mobile phone numbers ");
Document. adduser. custel. Focus ();
Return false;
}
If (! Document. adduser. cusemail. value. Match (/^. + @. + $ /)){
Alert ("prompt: enter a valid Email Address ");
Document. adduser. cusemail. Focus ();
Return false;
}
}
</SCRIPT>
For example, see the registered member in my self-developed web platform www.sanyalanhua.com .. Various comments are posted on specific applications, so that you can share and learn together ..