83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
function validate_form(minlength) {
|
|
var user = validate_username();
|
|
var pass = validate_password(minlength);
|
|
|
|
return validate_confirm() && pass && user;
|
|
}
|
|
|
|
function validate_confirm() {
|
|
var password = document.getElementById("newpassword");
|
|
var confirm = document.getElementById("confirm_password");
|
|
|
|
if (password.value != confirm.value) {
|
|
confirm.classList.add("errorinput");
|
|
document.getElementById("confirm-msg").classList.add("errormsg");
|
|
return false;
|
|
}
|
|
|
|
confirm.classList.remove("errorinput");
|
|
document.getElementById("confirm-msg").classList.remove("errormsg");
|
|
|
|
return true;
|
|
}
|
|
|
|
function validate_username() {
|
|
var username = document.getElementById("username");
|
|
var forbidden = /[*?!'\^+%\&/()=}{\$#;,\\"]+/;
|
|
|
|
if (username.value.length > 64 || forbidden.test(username.value) == true)
|
|
{
|
|
document.getElementById("username-msg").classList.add("errormsg");
|
|
username.classList.add("errorinput");
|
|
return false;
|
|
}
|
|
|
|
document.getElementById("username-msg").classList.remove("errormsg");
|
|
username.classList.remove("errorinput");
|
|
return true;
|
|
}
|
|
|
|
function validate_password(minlength) {
|
|
// Did the checks pass ?
|
|
var status = true;
|
|
// Target element
|
|
var password = document.getElementById("newpassword");
|
|
// Check the length
|
|
if (password.value.length < minlength)
|
|
{
|
|
status = false;
|
|
document.getElementById("minlen").classList.add("errormsg");
|
|
}
|
|
else
|
|
document.getElementById("minlen").classList.remove("errormsg");
|
|
// Look for a digit
|
|
if (/.*\d/.test(password.value) != true) {
|
|
status = false;
|
|
document.getElementById("digit").classList.add("errormsg");
|
|
}
|
|
else
|
|
document.getElementById("digit").classList.remove("errormsg");
|
|
// Look for a lowercase char
|
|
if (/.*[a-z]/.test(password.value) != true) {
|
|
status = false;
|
|
document.getElementById("lower").classList.add("errormsg");
|
|
}
|
|
else
|
|
document.getElementById("lower").classList.remove("errormsg");
|
|
// Look for an uppercase char
|
|
if (/.*[A-Z]/.test(password.value) != true) {
|
|
status = false;
|
|
document.getElementById("upper").classList.add("errormsg");
|
|
}
|
|
else
|
|
document.getElementById("upper").classList.remove("errormsg");
|
|
// Change the color of the inputbox
|
|
if (status == false)
|
|
{
|
|
password.classList.add("errorinput");
|
|
}
|
|
else
|
|
password.classList.remove("errorinput");
|
|
|
|
return status;
|
|
} |