Javascript verification function code

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.