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.
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; }
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; }
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; }
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!