Heim  >  Artikel  >  Web-Frontend  >  js几个验证函数代码_表单特效

js几个验证函数代码_表单特效

WBOY
WBOYOriginal
2016-05-16 18:31:32744Durchsuche
复制代码 代码如下:

//检查是否非空
function notEmpty(obj, msg)
{
str = obj.value;
str1 = "";
for (i = 0; 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;
}
}
//检查密码是否相同
function isSamePwd(objPwd1, objPwd2, msg)
{
pwd1 = objPwd1.value;
pwd2 = objPwd2.value;
if (pwd1 != pwd2)
{
if (null == msg)
{
alert("密码不相同!");
}
else
{
alert(msg);
}
objPwd2.value = "";
objPwd2.focus();
return false;
}
else
{
return true;
}
}
//检查邮件地址
function isEmail(obj, msg)
{
ch = obj.value;
if((ch.indexOf("@") {
if (null == msg)
{
alert("Email不正确!");
}
else
{
alert(msg);
}
obj.select();
return false;
}
else
{
return true;
}
}

复制代码 代码如下:


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn