Home  >  Article  >  Web Front-end  >  JS verification that commas separate Chinese letters and numbers_javascript skills

JS verification that commas separate Chinese letters and numbers_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:04:251690browse

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>

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

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 input to 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

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

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> 

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

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

Statement:
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