Have you ever had to fill out a form that asks you to enter twice the password for a service? Creating this system to confirm the data entered is not particularly complex, it takes a few lines of JavaScript on the principle that everyone of you to be able to create an online form and go directly to relevant code to the script:
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;"><script type="text/javascript"> <!-- controllo sulla validità della password --> var ck_password = /^[A-Za-z0-9]{8,12}$/; <!-- definizione delle variabili --> function validate(form){ var password = form.password.value; var confermapassword = form.confermapassword.value; <!-- array degli errori --> var errors = []; <!-- controllo sugli input --> if (!ck_password.test(password)) { errors[errors.length] = "La password deve contenere almeno 8 e massimo 12 caratteri alfanumerici."; } if (confermapassword != password) { errors[errors.length] = "Le password non coincidono."; } <!-- controllo sulla presenza di errori --> if (errors.length > 0) { reportErrors(errors); return false; } return true; } <!-- conteggio degli errori --> function reportErrors(errors){ var msg = "Inserisci i campi obbligatori...\n"; for (var i = 0; i<errors.length; i++) { var numError = i + 1; msg += "\n" + numError + ". " + errors[i]; } <!-- notifiche di errore --> alert(msg); } </script></span> <script type="text/javascript"> <! - check the validity of the password -> var ck_password = / ^ [A-Za-z0-9] {8.12} $ /; <! - definition of Variables -> function validate (form) {var password = form.password.value; var = confermapassword form.confermapassword.value; <! - array error -> var errors = []; <! - control over input -> if (! ck_password.test (password)) {errors [errors.length] = "Your password must contain at least 8 and up to 12 alphanumeric characters."} if (confermapassword! = password) {errors [errors. length] = "Passwords do not match."} <! - control over the errors -> if (errors.length> 0) {reportErrors (errors) return false;} return true;} <! - error count -> reportErrors function (errors) {var msg = "Enter the required fields ... \ n" for (var i = 0; i <errors.length i + +) {var numError = i + 1; msg + = "\ n" + numError + "." + errors [i];} <! - bug reports -> alert (msg);} </ script></span>
The script can be easily integrated with other variables and other controls for the client side validation of form input.
Related posts: