JS can only input numbers and English, Chinese, all English code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax code expression function javascript replace return text

English, Chinese, all English code
Below we provide a few common JS verification code, restrictions can only input numbers and English JS code restrictions can only input full-width characters English judgment function regular expression limit can only enter Chinese

Only numbers and English can be entered with regular expression restrictions: onkeyup= "Value=value.replace (/[w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') "restricts the use of regular expressions to only Chinese:

Onkeyup= "Value=value.replace (/[^u4e00-u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^u4e00-u9fa5]/g, ') "restricts only full-width characters in regular expression:

Onkeyup= "Value=value.replace (/[^uff00-uffff]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^uff00-uffff]/g, ') "
/*
The English judgment function, returns True is all English, returns false to indicate not all is English
*/

function Isletter (str) {
if ("" ==str) {
return false;
}
for (var i=0;i var c = Str.charat (i);
if (c< "a" | | C> "Z") && (c< "a" | | C> "Z")) {
return false;
}
}
return true;
}

Related Article

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.