Home > Web Front-end > JS Tutorial > body text

JS verification that commas separate Chinese letters and numbers_javascript skills

WBOY
Release: 2016-05-16 15:04:25
Original
1748 people have browsed it

Without further ado, I will just post the code for you. The specific code is as follows:

<script type="text/javascript"> 
var refid='dasdasd,dadsad'; 
var reg =/^([\u0391-\uFFE5\d\w,])*([\u0391-\uFFE5\d\w]+)$/; 
if(refid != "")
{ 
if(reg.exec(refid))
{ 
alert('验证通过'); 
}else 
{ 
alert('验证失败'); 
} 
}
</script>
Copy after login

The code is simple and easy to understand. If you have any good suggestions, you are welcome to make them and learn and make progress together!

Supplement: Validate Chinese, numbers, and letters in the text box in JS

1. Determine whether the text is English, numbers and Chinese characters

var reg = /^(/w|[/u4E00-/u9FA5])*$/; 
if(arr=username.match(reg)) 
{ 
ti=1; 
return ture; 
} 
else 
{ 
alert("用户名只允许为英文,数字和汉字的混合,/n请检查是否前后有空格或者其他符号"); 
ti=0; 
return false; 
}
Copy after login

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,''))" 
Copy after login

Use regular expressions to limit input to full-width characters:

onkeyup="value=value.replace(/[^/uFF00-/uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/uFF00-/uFFFF]/g,''))" 
Copy after login

Use regular expressions to limit input to numbers:

onkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))" 
Copy after login

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,''))" 
Copy after login

Number

<script> 
function check() 
{ 
if(!isNaN(document.all.form.str.value)) 
{ 
alert("数字"); 
} 
</script> 
Copy after login

letters

<script> 
function check() 
{ 
var str = /[a-zA-Z]/; 
if(str.test(document.all.form.str.value)) 
{ 
alert("字母"); 
} 
} 
</script> 
<form name="form" action="" onsubmit="return check();"> 
<input type=text name=str> 
<input type=submit> 
<form> 
Copy after login

-------------------------------------------------- ----------------------------------

/^[0-9a-zA-Z]+$/

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