jsは数字、字母、中国語を判断します.


js    ,  ,   
1. 

var reg = /^(\w|[\u4E00-\u9FA5])*$/; 
if(arr=username.match(reg)) 
{ 
ti=1; 
return ture; 
} 
else 
{ 
alert("         ,        ,
"); ti=0; return false; } 2. : :onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" : onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))" :onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" :onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" <script> function check() { if(!isNaN(document.all.form.str.value)) { alert(" "); } </script> <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> --------------------------------------------------- /** * javascript ( ) * * , String * .js , * * * ----------- -------------------------------- * Trim * Occurs * isDigit * isAlpha * isNumber * lenb * isInChinese * isEmail email * isDate , * isInList * isInList */ /*** ***/ String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } /*** ***/ String.prototype.Occurs = function(ch) { // var re = eval("/[^"+ch+"]/g"); // return this.replace(re, "").length; return this.split(ch).length-1; } /*** ***/ String.prototype.isDigit = function() { var s = this.Trim(); return (s.replace(/\d/g, "").length == 0); } /*** ***/ String.prototype.isAlpha = function() { return (this.replace(/\w/g, "").length == 0); } /*** ***/ String.prototype.isNumber = function() { var s = this.Trim(); return (s.search(/^[+-]?[0-9.]*$/) >= 0); } /*** ***/ String.prototype.lenb = function() { return this.replace(/[^\x00-\xff]/g,"**").length; } /*** ***/ String.prototype.isInChinese = function() { return (this.length != this.replace(/[^\x00-\xff]/g,"**").length); } /*** email ***/ 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); } /*** , ***/ String.prototype.isDate = function() { var p; var re1 = /(\d{4})[ ./-](\d{1,2})[ ./-](\d{1,2})[ ]?$/; var re2 = /(\d{1,2})[ ./-](\d{1,2})[ ./-](\d{2})[ ]?$/; var re3 = /(\d{1,2})[ ./-](\d{1,2})[ ./-](\d{4})[ ]?$/; 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; } /*** ***/ String.prototype.isInList = function(list) { var re = eval("/["+list+"]/"); return re.test(this); } /// <summary> /// /// </summary> /// <returns> , , </returns> String.prototype.IsDigit = function() { var reg = /^\d+$/g; return reg.test(this); } /// <summary> /// /// </summary> /// <returns> , , </returns> String.prototype.IsAlphaDigit = function() { var reg = /^[a-zA-Z0-9]+$/g; return reg.test(this); } /// <summary> /// 、 /// </summary> /// <returns> 、 , , </returns> String.prototype.IsAlpha = function() { var reg = /^\w+$/g; return reg.test(this); }