js表单验证
function checktruename(truename){
var str=truename;
//在JavaScript中,正则表达式只能使用"/"开头和结束,不能使用双引号
var Expression=/[^\u4E00-\u9FA5]/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
function $(id)
{
return document.getElementById(id);
}
//检查是否非空
function notEmpty(obj, msg)
{
str = obj.value;
str1 = "";
for (i = 0; i < str.length; i++)
{
if (str.charAt(i) != " ")
{
str1 = str.substr(i, str.length);
break;
}
}
if (str1 == "")
{
alert(msg);
obj.value = "";
obj.focus();
return false;
}
else
{
return true;
}
}
//检查是否为数字
function isNumber(obj, msg)
{
if(isNaN(obj.value))
{
if (undefined == msg)
{
msg = "请输入数字!";
}
alert(msg);
obj.select();
return false;
}
else
{
return true;
}
&n