Js login and registration verification, js login registration verification
I often write js verification, which is very troublesome. I will sort it out and paste it for later use. I am not so familiar with the details here. I am confident that you can understand the meaning of the Code.
Logon Verification:
Jsp page code:
<Form action = "userLogin. action "method =" post "onsubmit =" return login (); "id =" loginForm "> Js verification code:
Function login () {// lele.info ("click to log on"); var userName = $ ("# uName "). val (); // lele.info (userName) var userPass = $ ("# uPass "). val (); // lele.info (userPass); if (userName = "" | userName = null) {alert ("userName cannot be blank"); return false ;} else if (userPass = "" | userPass = null) {alert ("password cannot be blank"); return false;} else {return true ;}}
Registration Verification:
JSP page code:
<Span style = "white-space: pre"> </span> <form action = "userRegister. action "method =" post "onsubmit =" return register (); ">
Js verification code:
function register() {if(!checkname()){return false;}else if (!checkpass()) {return false;} else if(!checkemail()){return false;} return true;}
Function checkname () {var name = document. getElementById ("uName "). value; var ts = document. getElementById ("namets"); if (name. length <3 | name. length> 15) {ts. innerHTML = "the username must be 3-15 characters long! "; Ts. style. color = "red"; return false ;}$. post ("checkUserName. action ", {" userName ": name}, function (data) {var d = $. parseJSON (data); // console. log (d. success); if (d. success! = True) {ts. innerHTML = 'user name already exists! '; Ts. style. color = 'red'; return true ;}}); ts. innerHTML =' user name can be used! '; Ts. style. color = 'green'; return true;} function checkpass () {var userPass = $ ("# uPass "). val (); var pts = document. getElementById ("passts"); if (userPass. length <6 | userPass. length> 15) {pts. innerHTML = "the password length must be between 6 and 15! "; Pts. style. color =" red "; return false;} pts. innerHTML =" the password is usable! "; Pts. style. color = "green"; return true;} function checkrpass () {var userPass = $ ("# uPass "). val (); var userRPass =$ ("# uRPass "). val (); var prts = document. getElementById ("passrts"); if (userPass! = UserRPass) {prts. innerHTML = "the two passwords are inconsistent! "; Prts. style. color =" red "; return false;} prts. innerHTML =" consistent input! "; Prts. style. color = "green"; return true;} function checkemail () {var userEmail = $ ("# uEmail "). val (); var ets = document. getElementById ("emailts"); if (! IsEmail (userEmail) {ets. innerHTML = "Incorrect email format! "; Ets. style. color =" red "; return false;} ets. innerHTML =" email can be used! "; Ets. style. color = "green"; return true;} function isEmail (str) {var reg =/[a-z0-9-] {} @ [a-z0-9 }. [a-z] {3}/; return reg. test (str );}
Js login verification problems
Function checklogin (){
If (document. getElementById ("UserName"). value = ""){
Alert ("Enter the user name! "); Return false ;}
Return true ;}.
Onsumbit: the method used to execute the form statement when it is submitted...
If you know how to use Java, ajax, and js to verify Registration and logon, just say,
If you use the ssh framework, you can upload the parameters to the action in ajax mode, and then go to the dao layer to check whether the database has a considerable user name, which is returned to the callback function in js, and then follow the prompts.
If ssh is not used, use a servlet to accept the parameters passed by the client, and then go to the database for retrieval. Then, the servlet returns the results to the callback function.