Copy codeThe Code is as follows: // check whether 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 whether it is a number
Function isNumber (obj, msg)
{
If (isNaN (obj. value ))
{
If (undefined = msg)
{
Msg = "enter a number! ";
}
Alert (msg );
Obj. select ();
Return false;
}
Else
{
Return true;
}
}
// Check whether the password is the same
Function isSamePwd (objPwd1, objPwd2, msg)
{
Pwd1 = objPwd1.value;
Pwd2 = objPwd2.value;
If (pwd1! = Pwd2)
{
If (null = msg)
{
Alert ("different passwords! ");
}
Else
{
Alert (msg );
}
ObjPwd2.value = "";
ObjPwd2.focus ();
Return false;
}
Else
{
Return true;
}
}
// Check the 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 codeThe Code is as follows: <script language = "javascript">
Function checkspace (checkstr ){
Var str = '';
For (I = 0; I <checkstr. length; I ++ ){
Str = str + '';
}
Return (str = checkstr );
}
Function checkfrm ()
{
If (checkspace (document. frm. title. value ))
{
Alert ('title cannot be blank ');
Document. frm. title. focus ();
Return false;
}
If (checkspace (document. frm. truename. value ))
{
Alert ("name required ");
Document. frm. truename. focus ();
Return false;
}
If (checkspace (document. frm. danwei. value ))
{
Alert ("organization name not filled ");
Document. frm. dianwei. focus ();
Return false;
}
If (checkspace (document. frm. dizhi. value ))
{
Alert ("the address cannot be blank ");
Document. frm. dizhi. focus ();
Return false;
}
If (checkspace (document. frm. content. value ))
{
Alert ("The message content department can be blank ");
Document. frm. content. focus ();
Return false;
}
If (checkspace (document. frm. email. value ))
{
Alert ("email cannot be blank ");
Document. frm. email. focus ();
Return false;
}
Return true;
}
</Script>