Two methods for determining whether the text box is empty in JS

Source: Internet
Author: User

CopyCodeThe Code is as follows: // the user name is not empty for verification.
Function checkusername (){
VaR name = document.myform.txt user; // here I think: name represents the text box of txtuser
If (name. value. Length = 0 ){
Alert ("Enter the user name ");
Name. Focus ();
Return false;
} Else {return true ;}
}
// Non-empty password verification + Validation
Function checkpass (){
VaR passmediadocument.myform.txt pass;
VaR rpass#document.myform.txt rpass;
If (Pass. value = ""){
Alert ("the password cannot be blank ");
Pass. Focus ();
Return false;
} Else if (Pass. value. Length <4 | pass. value. length> 16 ){
Alert ("the password must be 4-16 characters long ");
Pass. Select ();
Return false;
} Else if (rpass. value! = Pass. Value ){
Alert ("confirming that the password is inconsistent with the password ");
Rpass. Select ();
Return false;
} Else {return true ;}
}

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.