Home  >  Article  >  Web Front-end  >  Two ways to determine whether a text box is empty in js_javascript skills

Two ways to determine whether a text box is empty in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:04:112394browse
Copy code The code is as follows:

//Username non-null verification
function checkUserName(){
var name = document.myform.txtUser; //Here I think: name represents the text box whose name is txtUser
if(name.value.length==0){
alert("Please Enter username");
name.focus();
return false;
}else{return true;}
}
//Password non-empty verification confirmation verification
function checkPass(){
var pass=document.myform.txtPass;
var rpass=document.myform.txtRPass;
if(pass.value==""){
alert("Password cannot be used is empty");
pass.focus();
return false;
}else if (pass.value.length<4 || pass.value.length>16){
alert( "The length of the password must be 4-16 characters");
pass.select();
return false;
}else if(rpass.value!=pass.value){
alert ("The confirmation password is inconsistent with the password input");
rpass.select();
return false;
}else{return true;}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn