Javascript restricts digital js and restricts input implementation code _ javascript skills

Source: Internet
Author: User
Tags microsoft frontpage
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:


Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.