Home Web Front-end JS Tutorial Regular expression to determine Chinese numbers and letters in js (example)_javascript skills

Regular expression to determine Chinese numbers and letters in js (example)_javascript skills

May 16, 2016 pm 05:52 PM
Chinese letter number

/*
判斷指定的內容是否為空,若為空則彈出警告框
*/
function isEmpty(theValue, strMsg){
if(theValue==""){
alert(strMsg "不能為空!");
return true;
}
return false;
}
/*
中文判斷函數,允許生僻字用英文“ *」取代
回傳true表示是符合條件,回傳false表示不符合
*/
function isChinese(str){
var badChar ="ABCDEFGHIJKLXYOPQRST ;
badChar = "0123456789";
badChar = " " " ";//半角與全角空格
badChar = "www.jb51.net不包含*或.的英文符號
if( ""==str){
return false;
}
for(var i=0;i var c = str.charAt(i);//字串str中的字元
if (badChar.indexOf(c) > -1){
return false;
}
}
return true;
}
/*
數字判斷函數,傳回true表示是全部數字,回傳false表示不全部是數字
*/
function isNumber(str){
if(""==str){
return false;
}
var reg = /D/;
return str.match(reg)==null;
}
/*
判斷給定的字串是否為指定長度的數字
是回傳true,不是回傳false
*/
function isNumber_Ex(str,len){
if(""==str){
return false;
}
if(str .length!=len){
return false;
}
if(!isNumber(str)){
return false;
}
return true;
}
/*
money判斷函數,允許第一位為"-"來表示欠錢
回傳true表示格式正確,回傳false表示格式錯誤
*/
function isMoney(str) {
if(""==str){
return false;
}
for(var i=0;i var c = str.charAt(i);
if(i ==0){
if(c!="-"&&(c
"9")){ return false;
}else if(c=="-"&&str.length ==1){
return false;
}
}else if(c
"9"){ return false;
}
}
return true true ;
}
/*
英文判斷函數,回傳true表示是全部英文,回傳false表示不全部是英文
*/
function isLetter(str){
if( ""==str){
return false;
}
for(var i=0;i var c = str.charAt(i);
if((c
"z ")&&(c"Z")){ return false;
}
}
return true;
}
/*
空格判斷,當包含有空格回傳false,當不包含一個空格回傳true
""不能被判斷
*/
function notInSpace(str){
if(""==str){
return false;
}
var badChar =" ";
badChar = " ";
for(var i=0;i var c = str.charAt(i);//字符串中的字符
if(badChar.indexOf(c) > -1){
return false;
}
}
return true;
}
/*
**號判斷函數,回傳true表示是**號,回傳false表示不符合規範
*/
function isFPH(str){
if(""==str){
return false;
}
for(var i=0;i var c = str.charAt(i);
if((c
"9") && (c!="-" )&&(c!=",")){ return false;
}
}
return true;
}
/*
電話判斷函數,允許「數字」、「;」、「-」、「(」、」)「,
true表示是電話號碼
*/
function isTelephone(str){
var trueChar = "() -;1234567890";
if(""==str){
return false;
}
for(var i=0;i var c = str.charAt(i);//字串str中的字元
if(trueChar.indexOf(c) == -1) return false;
}
return true;
}
/**
學制可以為1-7,也可以為3.5這種形式,不能超過7年或低於1年
*/
function isXZ(str){
if(""==str){
return false;
}
var reg = /^[1-6](.5)?$ /;
var r = str.match(reg);
if(null!=r){
return true;
}else{
if(str=="7") {
return true;
}else{
return false;
}
}
}
/*
判斷憑證編號是否符合要求,憑證編號包含中文、數字、大小寫字母、(、)、-
是回傳true,不是回傳false
*/
function isZSBH(str){
if(""==str){
return false;
}
for(var i=0;i var c = str.charAt(i);
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
alpha = "abcdefghijMNOPQRSTUVWXYZ";
alpha = "abcdefghijmnopq. alpha = "()-";
if(!isChinese(c)&&!isNumber(c)&&alpha.indexOf(c)==-1){
return false;
}
}
return true;
}
/*
身分證判斷函數,是傳回true,不是回傳false
15位元數字,18位元數字或最後一位為X(大寫)
*/
function isSFZ(str){
if(""==str){
return false;
}
if(str.length!=15&&str.length!= 18){//身分證長度不正確
return false;
}
if(str.length==15){
if(!isNumber(str)){
return false ;
}
}else{
str1 = str.substring(0,17);
str2 = str.substring(17,18);
alpha = "X0123456789"; >if(!isNumber(str1)||alpha.indexOf(str2)==-1){
return false;
}
}
return true;
}
/ *
得到今天的年,月,日
呼叫方法:today = new getToday(); 則today.year為今天的年以此類推
*/
function getToday(){
this.now = new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this. now.getDate();
}

js determines numbers, letters, Chinese
1.
var reg = /^(w|[u4E00-u9FA5])*$/;
if(arr=username.match( reg))
{
ti=1;
return ture;
}
else
{
alert("Username is only allowed to be a mixture of English, numbers and Chinese characters ,nPlease check whether there are spaces or other symbols before and after");
ti=0;
return false;
}
2. Use regular expressions to limit the input content of the text box in the web form:
Use regular expressions to limit input to Chinese only: onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData ('text').replace(/[^u4E00-u9FA5]/g,''))"
Use regular expressions to limit the input of only full-width characters: onkeyup="value=value.replace(/[^uFF00 -uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"
Use regular expressions to limit input to numbers: onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text') .replace(/[^d]/g,''))"
Use regular expressions to limit input to numbers and English only: onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"

Number


Letters







-------------------------- -------------------------------------
/**
* Some commonly used JavaScript functions (methods)
*
* For ease of use, all methods are written as String objects
* Save them as .js files to easily expand string objects Function
*
* Method name function
* ----------- ----------------------- ----------
* Trim removes the first space
* Occurs counts the number of occurrences of the specified character
* isDigit checks whether it consists of numbers
* isAlpha checks whether it consists of numbers, letters and Underscores
* isNumber Check whether it is a number
* lenb Return the number of bytes
* isInChinese Check whether it contains Chinese characters
* isEmail Simple email check
* isDate Simple date check, successfully return the date Object
* isInList Checks whether there is a character character in the list
* isInList Checks whether there is a character character
in the list*/
/*** Remove leading and trailing spaces ***/
String.prototype.Trim = function() {
return this.replace(/(^s*)|(s*$)/g, "");
}
/*** Count the number of occurrences of the specified character ***/
String.prototype.Occurs = function(ch) {
// var re = eval("/[^" ch "]/g") ;
// return this.replace(re, "").length;
return this.split(ch).length-1;
}
/*** Check if it consists of numbers ***/
String.prototype.isDigit = function() {
var s = this.Trim();
return (s.replace(/d/g, "").length == 0);
}
/*** Check if it consists of numbers, letters and underscores ***/
String.prototype.isAlpha = function() {
return (this.replace(/w/g, "").length == 0);
}
/*** Check if it is a number ***/
String.prototype.isNumber = function() {
var s = this.Trim();
return (s.search(// ^[ -]?[0-9.]*$/) >= 0);
}
/*** Return the number of bytes ***/
String.prototype.lenb = function() {
return this.replace(/[^x00-xff]/g,"**").length;
}
/*** Check if it contains Chinese characters ***/
String.prototype.isInChinese = function( ) {
return (this.length != this.replace(/[^x00-xff]/g,"**").length);
}
/*** Simple email check ***/
String.prototype.isEmail = function() {
var strr;
var mail = this;
var re = /(w @w .w )(.{0,1}w* )(.{0,1}w*)/i;
re.exec(mail);
if(RegExp.$3!="" && RegExp.$3!="." && RegExp.$2! =".")
strr = RegExp.$1 RegExp.$2 RegExp.$3;
else
 if(RegExp.$2!="" && RegExp.$2!=".")
strr = RegExp.$1 RegExp.$2;
else
strr = RegExp.$1;
return (strr==mail);
}
/*** Simple date check, successfully returns date object ***/
String.prototype.isDate = function() {
var p;
var re1 = /(d{4})[Year./-](d{1,2})[Month./-]( d{1,2})[Day]?$/;
var re2 = /(d{1,2})[Month./-](d{1,2})[Day./-]( d{2})[year]?$/;
var re3 = /(d{1,2})[month./-](d{1,2})[day./-](d{ 4})[year]?$/;
if(re1.test(this)) {
p = re1.exec(this);
return new Date(p[1],p[2 ],p[3]);
}
if(re2.test(this)) {
p = re2.exec(this);
return new Date(p[3],p [1],p[2]);
}
if(re3.test(this)) {
p = re3.exec(this);
return new Date(p[3] ,p[1],p[2]);
}
return false;
}
/*** Check if there is a character character in the list ***/
String.prototype.isInList = function(list) {
var re = eval("/[" list "]/"); <script> <BR>function check() <BR>{ <BR>if(!isNaN(document.all.form.str.value)) <BR>{ <BR>alert("数字"); <BR>} <BR></script>return re.test(this); <script> <BR>function check() <BR>{ <BR>var str = /[_a-zA-Z]/; <BR>if(str.test(document.all.form.str.value)) <BR>{ <BR>alert("字母"); <BR>} <BR>} <BR></script>}
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set Chinese in Call of Duty: Warzone mobile game How to set Chinese in Call of Duty: Warzone mobile game Mar 22, 2024 am 08:41 AM

Call of Duty Warzone is a newly launched mobile game. Many players are very curious about how to set the language of this game to Chinese. In fact, it is very simple. Players only need to download the Chinese language pack, and then You can modify it after using it. The detailed content can be learned in this Chinese setting method introduction. Let us take a look together. How to set the Chinese language for the mobile game Call of Duty: Warzone 1. First enter the game and click the settings icon in the upper right corner of the interface. 2. In the menu bar that appears, find the [Download] option and click it. 3. Select [SIMPLIFIEDCHINESE] (Simplified Chinese) on this page to download the Simplified Chinese installation package. 4. Return to the settings

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

How to display Chinese characters correctly in PHP Dompdf How to display Chinese characters correctly in PHP Dompdf Mar 05, 2024 pm 01:03 PM

How to display Chinese characters correctly in PHPDompdf When using PHPDompdf to generate PDF files, it is a common challenge to encounter the problem of garbled Chinese characters. This is because the font library used by Dompdf by default does not contain Chinese character sets. In order to display Chinese characters correctly, we need to manually set the font of Dompdf and make sure to select a font that supports Chinese characters. Here are some specific steps and code examples to solve this problem: Step 1: Download the Chinese font file First, we need

How to set Excel table to display Chinese? Excel switching Chinese operation tutorial How to set Excel table to display Chinese? Excel switching Chinese operation tutorial Mar 14, 2024 pm 03:28 PM

Excel spreadsheet is one of the office software that many people are using now. Some users, because their computer is Win11 system, so the English interface is displayed. They want to switch to the Chinese interface, but they don’t know how to operate it. To solve this problem, this issue The editor is here to answer the questions for all users. Let’s take a look at the content shared in today’s software tutorial. Tutorial for switching Excel to Chinese: 1. Enter the software and click the "File" option on the left side of the toolbar at the top of the page. 2. Select "options" from the options given below. 3. After entering the new interface, click the “language” option on the left

An effective way to fix Chinese garbled characters in PHP Dompdf An effective way to fix Chinese garbled characters in PHP Dompdf Mar 05, 2024 pm 04:45 PM

Title: An effective way to repair Chinese garbled characters in PHPDompdf. When using PHPDompdf to generate PDF documents, garbled Chinese characters are a common problem. This problem usually stems from the fact that Dompdf does not support Chinese character sets by default, resulting in Chinese content not being displayed correctly. In order to solve this problem, we need to take some effective ways to fix the Chinese garbled problem of PHPDompdf. 1. Use custom font files. An effective way to solve the problem of Chinese garbled characters in Dompdf is to use

Will wwe2k24 have Chinese? Will wwe2k24 have Chinese? Mar 13, 2024 pm 04:40 PM

"WWE2K24" is a racing sports game created by Visual Concepts and was officially released on March 9, 2024. This game has been highly praised, and many players are eagerly interested in whether it will have a Chinese version. Unfortunately, so far, "WWE2K24" has not yet launched a Chinese language version. Will wwe2k24 be in Chinese? Answer: Chinese is not currently supported. The standard version of WWE2K24 in the Steam Chinese region is priced at 199 yuan, the deluxe version is 329 yuan, and the commemorative edition is 395 yuan. The game has relatively high configuration requirements, and there are certain standards in terms of processor, graphics card, or running memory. Official recommended configuration and minimum configuration introduction:

Tips for solving Chinese garbled characters when writing txt files with PHP Tips for solving Chinese garbled characters when writing txt files with PHP Mar 27, 2024 pm 01:18 PM

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

How to change Google Chrome to Chinese mode? How to change Google Chrome to Chinese mode? Mar 13, 2024 pm 07:31 PM

How to change Chinese to English in Google Chrome? Some friends want to set Google Chrome to English so that they can continuously improve their English during use. So how to set it to English? Google Chrome is Chinese by default. Below, I will show you how to set the language of Google Chrome to English. Let’s take a look. Setting steps: 1. Open [Google Chrome], as shown in the figure below. 2. Click the [three dots] menu in the upper right corner of the Google Chrome interface, as shown in the figure below. 3. After entering the menu page, find [Settings], as shown in the figure below. 4. After entering the settings page, click the [Language] option, as shown in the figure below. 5. Select [Add Language] in the language interface, as shown in the figure below.

See all articles