From 0ff31fecbe96f0c81a76ab77ff10d1b6bb238eca Mon Sep 17 00:00:00 2001 From: adyanf <adyanaufalf@gmail.com> Date: Thu, 5 Oct 2017 12:01:58 +0700 Subject: [PATCH] adding wrong input for username and email signup form --- css/auth.css | 6 +++++- js/validation.js | 55 +++++++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/css/auth.css b/css/auth.css index d3d7a1a..3cd56c1 100644 --- a/css/auth.css +++ b/css/auth.css @@ -134,10 +134,14 @@ body { width: 47%; } -.form-signup .form-group span { +.form-signup .form-group span i { display: none; } +.form-signup .form-group span i:nth-of-type(2) { + color: #B33A3A; +} + .form-signup input[type=checkbox] { margin-top: 15px; } diff --git a/js/validation.js b/js/validation.js index e163a23..a549a65 100644 --- a/js/validation.js +++ b/js/validation.js @@ -13,37 +13,54 @@ function getUsernameValidation(){ var response = xmlhttp.responseText; console.log(response); if(response === "true"){ + document.getElementById("wrongUsername").style.display = "none"; document.getElementById("checkUsername").style.display = "block"; } else { document.getElementById("checkUsername").style.display = "none"; + document.getElementById("wrongUsername").style.display = "block"; } } } xmlhttp.send(); } +function validateEmail(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,}))$/; + return re.test(email); +} + function getEmailValidation(){ - var xmlhttp = new XMLHttpRequest(); - if(!xmlhttp){ - return; - } var email = document.getElementById("email"); - console.log(email); - var url = "validation.php?e=" + email.value; - console.log(url); - xmlhttp.open("GET", url, true); - xmlhttp.onreadystatechange = function(){ - if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ - var response = xmlhttp.responseText; - console.log(response); - if(response === "true"){ - document.getElementById("checkEmail").style.display = "block"; - } - else { - document.getElementById("checkEmail").style.display = "none"; + console.log(email.value); + console.log(validateEmail(email.value)); + if (!validateEmail(email.value)){ + document.getElementById("checkEmail").style.display = "none"; + document.getElementById("wrongEmail").style.display = "block"; + } + else { + var xmlhttp = new XMLHttpRequest(); + if(!xmlhttp){ + return; + } + console.log(email); + var url = "validation.php?e=" + email.value; + console.log(url); + xmlhttp.open("GET", url, true); + xmlhttp.onreadystatechange = function(){ + if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ + var response = xmlhttp.responseText; + console.log(response); + if(response === "true"){ + document.getElementById("wrongEmail").style.display = "none"; + document.getElementById("checkEmail").style.display = "block"; + } + else { + document.getElementById("checkEmail").style.display = "none"; + document.getElementById("wrongEmail").style.display = "block"; + } } } - } - xmlhttp.send(); + xmlhttp.send(); + } } \ No newline at end of file -- GitLab