diff --git a/code/html/custom.js b/code/html/custom.js index 2b37998c..ba542dd6 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -164,21 +164,35 @@ function validatePassword(password) { ); } -function validateForm(form) { +function validateFormPasswords(form) { + var passwords = $("input[name='adminPass1'],input[name='adminPass2']", form); + var adminPass1 = passwords.first().val(), + adminPass2 = passwords.last().val(); + + var formValidity = passwords.first()[0].checkValidity(); + if (formValidity && (adminPass1.length === adminPass2.length === 0)) { + return true; + } + + var validPass1 = validatePassword(adminPass1), + validPass2 = validatePassword(adminPass2); - // password - var adminPass1 = $("input[name='adminPass']", form).first().val(); - if (!validatePassword(adminPass1)) { + if (formValidity && validPass1 && validPass2) { + return true; + } + + if (!formValidity || (adminPass1.length > 0 && !validPass1)) { alert("The password you have entered is not valid, it must be 8..63 characters and have at least 1 lowercase and 1 uppercase / number!"); - return false; } - var adminPass2 = $("input[name='adminPass_confirm']", form).last().val(); if (adminPass1 !== adminPass2) { alert("Passwords are different!"); - return false; } + return false; +} + +function validateFormHostname(form) { // RFCs mandate that a hostname's labels may contain only // the ASCII letters 'a' through 'z' (case-insensitive), // the digits '0' through '9', and the hyphen. @@ -196,13 +210,17 @@ function validateForm(form) { return true; } - if (!re_hostname.test(hostname.val())) { - alert("Hostname cannot be empty and may only contain the ASCII letters ('A' through 'Z' and 'a' through 'z'), the digits '0' through '9', and the hyphen ('-')! They can neither start or end with an hyphen."); - return false; + if (re_hostname.test(hostname.val())) { + return true; } - return true; + alert("Hostname cannot be empty and may only contain the ASCII letters ('A' through 'Z' and 'a' through 'z'), the digits '0' through '9', and the hyphen ('-')! They can neither start or end with an hyphen."); + return false; +} + +function validateForm(form) { + return validateFormPasswords(form) && validateFormHostname(form); } function getValue(element) { @@ -235,7 +253,7 @@ function addValue(data, name, value) { ]; - // join both adminPass and ..._confirm + // join both adminPass 1 and 2 if (name.startsWith("adminPass")) { name = "adminPass"; } diff --git a/code/html/index.html b/code/html/index.html index bdf1e7bf..a852d1ef 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -28,7 +28,7 @@
-
+
@@ -41,14 +41,14 @@
- - + +
- - + +
@@ -62,7 +62,7 @@
- +
@@ -533,10 +533,10 @@
- +
- +