javascript - Validating form input before submiting form -
i've learned make login form , planning validate 2 values ( email , password ) , use condition true or false .
i have code this
function uservalid(email) { var usr = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$\i/ ; return usr.test(email); }; function passvalid(password) { var passw = /^[a-za-z]\w{7,14}$/; return passw.test(password); };
the code above use validating email , password in form , think if passing value function (for example passing value email uservalid() function) return true/false.
i plan create validating form or login form first check user email & password valid before submit (lets server).
and think logic :
- if both values true login success
- if 1 of values true login failed
- if both values false login failed
- else (the value must empty or null) please insert email , password
and on
my question how create conditional statement above case, , of course in javascript :) thanks.
i don't know how acces email , password, should work if fill in.
if ( uservalid(email) == true && passvalid(password) == true ) { //login succes code } else if ( uservalid(email) == false || passvalid(password) == false ){ //login failure code } else { //the "please insert" code }
the &&
operater (and) returns true if both values true.
the ||
operater (or) returns true if @ least 1 of values true.
this can done easier, should work this.
you can add code check if password , username empty, don't think that's necesarry.
Comments
Post a Comment