All checks were successful
continuous-integration/drone/push Build is passing
108 lines
3.3 KiB
JavaScript
108 lines
3.3 KiB
JavaScript
function validate_username_form(minlength) {
|
|
var user = validate_username();
|
|
var pass = validate_password(minlength);
|
|
|
|
if (validate_confirm() && pass && user) {
|
|
disable_submit(false);
|
|
return true;
|
|
}
|
|
|
|
disable_submit(true);
|
|
return false;
|
|
}
|
|
|
|
function disable_submit(status) {
|
|
document.getElementById("submit").disabled = status;
|
|
}
|
|
|
|
function validate_email() {
|
|
var email = document.getElementById("email");
|
|
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
|
|
if (re.test(email.value) != true) {
|
|
disable_submit(true);
|
|
email.classList.add("errorinput");
|
|
return false;
|
|
}
|
|
|
|
|
|
disable_submit(false);
|
|
email.classList.remove("errorinput");
|
|
return true;
|
|
}
|
|
|
|
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");
|
|
disable_submit(true);
|
|
return false;
|
|
}
|
|
|
|
document.getElementById("username-msg").classList.remove("errormsg");
|
|
username.classList.remove("errorinput");
|
|
disable_submit(false);
|
|
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;
|
|
} |