Commit 6b0345a2 authored by Erma Safira Nurmasyita's avatar Erma Safira Nurmasyita
Browse files

[ADD] Blank field validation in Login

parent 3cebdf20
const BLANK_SPACE_REGEX = /^\s*$/;
function isValidated(){
username = document.getElementById("userame").value;
pass = document.getElementById("password").value;
if (username == "" || pass == ""){
var validation = true;
validation &= validateBlankInput("username");
validation &= validateBlankInput("password");
if (validation != 1) {
alert("All fields must be filled.");
}
return validation == 1;
}
function validateBlankInput(inputID) {
var value = document.getElementById(inputID).value;
if (value == "" || BLANK_SPACE_REGEX.test(value)) {
showInvalidInput(inputID);
return false;
} else {
hideInvalid(inputID);
return true;
}
}
function showInvalidInput(inputID) {
highlightInvalid(inputID);
}
function hideInvalid(inputID) {
var border = document.getElementById(inputID).style.border;
if (border == "2px solid red") {
document.getElementById(inputID).style.border = "";
}
}
function highlightInvalid(inputID) {
var border = document.getElementById(inputID).style.border;
if (border == "") {
document.getElementById(inputID).style.border = "2px solid red";
}
}
\ No newline at end of file
......@@ -9,8 +9,8 @@
<div class="content">
<h1>LOGIN</h1>
<form action="../login/login.php" onsubmit="return (isValidated())" method = "POST">
<p>Username <input type="text" name="username" ></p>
<p>Password <input type="password" name="password" ></p>
<p>Username <input id="username" type="text" name="username" ></p>
<p>Password <input id="password" type="password" name="password" ></p>
<p id="account_existence"><a href="/registration">Don\'t have an account?</a></p>
<input id="submit_button" type="submit" value="LOGIN">
</form>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment