In my work, I often encounter js restrictions on input. This article will introduce the implementation principles in detail. If you need them, refer
1. Only Chinese characters can be entered
The Code is as follows:
2. Only numbers can be entered
The Code is as follows:
Chinese characters cannot be entered.
The Code is as follows:
Enter a number and a decimal point:
The Code is as follows:
Onkeyup = "value = value. replace (/[^ \ d {1 ,}\. \ d {1 ,}| \ d {1,}]/g ,'')"
Javascript can only enter numbers and ":".
Only numbers and ":" are allowed. For example, they can be used when you enter the time.
The Code is as follows:
Only letters and equal signs are allowed, and Chinese characters are not allowed.
Other things:
Only scripts with numbers can be entered --
The Code is as follows:
The upper half means that only numbers can be typed on the keyboard, and only numbers can be pasted in the lower half.
The Code is as follows:
3. JavaScript restrictions: only numbers and English letters can be entered
The Code is as follows:
Function isregname (checkobj)
{
Var checkOK = "0123456789-_ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
Var checkStr = checkobj;
Var allValid = true;
Var decPoints = 0;
For (I = 0; I <checkStr. length; I ++)
{
Ch = checkStr. charAt (I );
For (j = 0; j <checkOK. length; j ++)
If (ch = checkOK. charAt (j ))
Break;
If (j = checkOK. length)
{
AllValid = false;
Break;
}
}
Return (allValid)
}
----------------
If (! (Isregname (obj. loginname. value ))){
Alert ("[Member Code] does not comply with the specifications. The Member Code can only be English letters or numbers ");
Obj. loginname. focus ();
Return (false );
}
If (! (Isregname (obj. password. value ))){
Alert ("[Password] does not comply with the specifications. The password can only be English letters or numbers ");
Obj. password. focus ();
Return (false );
}
4. javascript can only enter input boxes of English letters and numbers
The Code is as follows:
5. You can use Javascript to check the text box and filter out non-0-9 characters.
The Code is as follows: