帮忙修改一下,验证是否英文和中文输入?(在线等给分)
小弟抄了一个JS,内容如下:
//自定义类别
function ChangeCategory()
{
CategoryName=prompt( "请输入英文品名(最多15个字符): ", " ");
if(!CategoryName) return;
if(CategoryName.length > 15){alert( "英文品名名称不能大于15个字符! ");return false;}
this.focus();
i=document.myform.cargo.length;
document.myform.cargo.options[i]=new Option(CategoryName,CategoryName);
document.myform.cargo.options[i].selected=true;
}
//菜单
var menuOffX=0 //菜单距连接文字最左端距离
var menuOffY=18 //菜单距连接文字顶端距离
var ie4=document.all&&navigator.userAgent.indexOf( "Opera ")==-1
var ns6=document.getElementById&&!document.all
===========================================================
请各位大哥帮我补充一下,我要验证:
CategoryName必须为英文输入 或 中文 输入 或 数字输入.
请分开帮我写一下验证的方法,可以吗??
------解决方案--------------------var strng= "中文的 "
var strng1= "中文的aa "
var strng2= "111 "
var strng3= "aaas "
var strng4= "111aaa "
function aaacheck(a) {
//var pat = /[^\x00-\xff]+/g; //这个是双字节的。就是说带标点符号。
var pat = /(^[\u4e00-\u9fa5]+$)|(^\d+$)|(^[a-z]+$)/gi; //这个好象带中文的。
if(pat.test(a)){
alert( "true ")
}else{
alert( "false ")
}
//alert(pat.test(strng))
}
aaacheck(strng)
aaacheck(strng1)
aaacheck(strng2)
aaacheck(strng3)
aaacheck(strng4)
------解决方案-------------------- <input type= "text " name= "name " maxlength= "20 " value= " " onkeypress= "return checkInput(); " />
...
function checkInput(){
return (event.keyCode > = 48 && event.keyCode <= 57) || (event.keyCode > = 65 && event.keyCode <= 90) || (event.keyCode > = 97 && event.keyCode <= 122);
}
就这个思路
------解决方案-------------------- <SCRIPT LANGUAGE= "JavaScript ">
<!--
do
{
CategoryName=prompt( "请输入英文品名(最多15个字符): ", " ");
}
while (!/^[\u4e00-\u9fa5\d\w]+$/.test(CategoryName) || CategoryName==null);
alert( 'OK ');
//-->
</SCRIPT>
------解决方案-------------------- <SCRIPT LANGUAGE= "JavaScript ">
<!--
do
{
CategoryName=prompt( "数字: ", " ");
}
while (!/^\d+$/.test(CategoryName) || CategoryName==null);
alert( 'OK ');
//-->
</SCRIPT>
<SCRIPT LANGUAGE= "JavaScript ">
<!--
do
{
CategoryName=prompt( "请输入英文品名(最多15个字符): ", " ");
}
while (!(/^[a-zA-Z]+$/.test(CategoryName) && CategoryName.length <15) || CategoryName==null);
alert( 'OK ');
//-->
</SCRIPT>
<SCRIPT LANGUAGE= "JavaScript ">
<!--
do
{
CategoryName=prompt( "中文: ", " ");
}
while (!/^[\u4e00-\u9fa5]+$/.test(CategoryName) || CategoryName==null);
alert( 'OK ');
//-->
</SCRIPT>