<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
/**
@param inputName 输入框的名字.
@param inputType 输入框类型,如QQ,Email,Phone 等
@param isNotNull 是否可以为空.'Y'-不能为空,'N'-可以为空
**/
function chechkTextBoxValue(inputName,inputType,isNotNull){
var obj=new Array();
var objReg=new Array();
var objMsg=new Array();
obj[0] = "Email";
obj[1] = "Phone";
obj[2] = "Mobile";
obj[3] = "Url";
obj[4] = "IdCard";
obj[5] = "Currency";
obj[6] = "Number0";
obj[7] = "Zip";
obj[8] = "QQ";
obj[9] = "Integer";
obj[10] = "Double";
obj[11] = "English";
obj[12] = "Chinese";
objReg[0] = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
objReg[1] = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/;
objReg[2] = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/;
objReg[3] = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
objReg[4] = /^\d{15}(\d{2}[A-Za-z0-9])?$/;
objReg[5] = /^\d+(\.\d+)?$/;
objReg[6] = /^\d+$/;
objReg[7] = /^[1-9]\d{5}$/;
objReg[8] = /^[1-9]\d{4,8}$/;
objReg[9] = /^[-\+]?\d+$/;
objReg[10] = /^[-\+]?\d+(\.\d+)?$/;
objReg[11] = /^[A-Za-z]+$/;
objReg[12] = /^[\u0391-\uFFE5]+$/;
objMsg[0] = "请输入正确的邮件地址.";
objMsg[1] = "请输入正确的固定电话.";
objMsg[2] = "请输入正确的移动电话.";
objMsg[3] = "请输入正确的URL."
objMsg[4] = "请输入正确的身份证件号码."
objMsg[5] = "请输入正确的货币.";
objMsg[6] = "请输入正确的数字.";
objMsg[7] = "请输入正确的邮编.";
objMsg[8] = "请输入正确的QQ号码.";
objMsg[9] = "请输入整数.";
objMsg[10] = "请输入浮点数.";
objMsg[11] = "请输入英文字母.";
objMsg[12] = "请输入汉字.";
var inputValue=inputName.value;
for(var i=0;i<obj.length;i++){
if(obj[i]==inputType){
if((inputValue.length>0||isNotNull=='Y')&&!objReg[i].test(inputValue)){
alert(objMsg[i]);
inputName.focus();
return false;
}
}
}
}
function testchechkTextBoxValue(){
var in1=document.getElementById("in1");
if(chechkTextBoxValue(in1,"QQ",'N')==false){
return false;
}
}
</script>
</head>
<body>
<input id="in1" type="text"/>
<input type="submit" value="验证" onclick="return testchechkTextBoxValue();"/>
</body>
</html>