Home > Web Front-end > JS Tutorial > js several verification function codes_form effects

js several verification function codes_form effects

WBOY
Release: 2016-05-16 18:31:32
Original
815 people have browsed it
Copy code The code is as follows:

//Check if it is not empty
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;
}
}
//Check if it is a number
function isNumber(obj, msg)
{
if(isNaN(obj.value ))
{
if (undefined == msg)
{
msg = "Please enter a number!";
}
alert(msg);
obj.select ();
return false;
}
else
{
return true;
}
}
//Check whether the passwords are the same
function isSamePwd( objPwd1, objPwd2, msg)
{
pwd1 = objPwd1.value;
pwd2 = objPwd2.value;
if (pwd1 != pwd2)
{
if (null == msg)
{
alert("Passwords are different!");
}
else
{
alert(msg);
}
objPwd2.value = "";
objPwd2.focus();
return false;
}
else
{
return true;
}
}
//check Email address
function isEmail(obj, msg)
{
ch = obj.value;
if((ch.indexOf("@") < 1) || (ch.indexOf( ".") < 1) || (ch.indexOf(".") == ch.length - 1))
{
if (null == msg)
{
alert ("Email is incorrect! ");
}
else
{
alert(msg);
}
obj.select();
return false;
}
else
{
return true;
}
}

Copy code The code is as follows:

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template