Home > Web Front-end > JS Tutorial > How to verify whether the input is Chinese in jquery

How to verify whether the input is Chinese in jquery

coldplay.xixi
Release: 2020-12-22 16:00:17
Original
3193 people have browsed it

Jquery method to verify whether the input is Chinese: 1. Numeric judgment function, returning true means all numbers, returning false means not all numbers; 2. Function to judge whether the input is Chinese.

How to verify whether the input is Chinese in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

Jquery method to verify whether the input is Chinese:

Example 1, function to determine whether the input is Chinese

Code example:

function ischinese(s){
    var ret=true;
    for(var i=0;i<s.length;i++)
    ret=ret && (s.charCodeAt(i)>=10000);
    return ret;
}
Copy after login

Example 2, Chinese judgment function, allows rare words to be replaced by English "*". Return true to indicate that the condition is met, and return false to indicate that it is not met.

Code example:

function isChinese(str){
var badChar ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
badChar += "abcdefghijklmnopqrstuvwxyz";
badChar += "0123456789";
badChar += " "+" ";//半角与全角空格
badChar += "不包含*或.的英文符号
if(""==str){
return false;
} // www.jquerycn.cn
for(var i=0;i var c = str.charAt(i);//字符串str中的字符
if(badChar.indexOf(c) > -1){
return false;
}
}
return true;
}
Copy after login

Example 3, digital judgment function, returns true to indicate that all numbers are, returns false to indicate that not all are numbers

Code example:

function isNumber(str){
if(""==str){
return false;
}
var reg = /\D/;
return str.match(reg)==null;
}
Copy after login

Related free learning recommendations: javascript (video)

The above is the detailed content of How to verify whether the input is Chinese in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template