From 095b6397941f4e6c65a25910215ab73dc8b11262 Mon Sep 17 00:00:00 2001 From: coolneng Date: Thu, 18 Jun 2020 08:12:23 +0200 Subject: [PATCH] Add user creation form validation --- src/forms/patient_create_form.php | 4 +-- src/forms/user_create_form.html | 3 +- src/validate_user.js | 47 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/validate_user.js diff --git a/src/forms/patient_create_form.php b/src/forms/patient_create_form.php index a3b6da1..ea2411b 100644 --- a/src/forms/patient_create_form.php +++ b/src/forms/patient_create_form.php @@ -7,7 +7,7 @@ - + -
+
diff --git a/src/forms/user_create_form.html b/src/forms/user_create_form.html index 92533a6..e3f6210 100644 --- a/src/forms/user_create_form.html +++ b/src/forms/user_create_form.html @@ -5,9 +5,10 @@ + - +
diff --git a/src/validate_user.js b/src/validate_user.js new file mode 100644 index 0000000..0ec3afd --- /dev/null +++ b/src/validate_user.js @@ -0,0 +1,47 @@ +function validateString(input){ + if(input == ""){ + return false; + } + return true; +} + +function validateEmail(input){ + var emailID = input; + atpos = emailID.indexOf("@"); + dotpos = emailID.lastIndexOf("."); + + if (atpos < 1 || ( dotpos - atpos < 2 )) { + return false; + } + return true; +} + + +function validateUser(){ + var name = document.forms["create_form"]["nombre"]; + var user = document.forms["create_form"]["usuario"]; + var password = document.forms["create_form"]["contraseƱa"]; + var email = document.forms["create_form"]["correo"]; + + if(!validateString(name.value)){ + alert("Introduce el nombre"); + return false; + } + + if(!validateString(user.value)){ + alert("Introduce el usuario"); + return false; + } + + if(!validateString(password.value)){ + alert("Introduce la contraseƱa"); + return false; + } + + if(!validateEmail(email.value)){ + alert("El correo proporcionado es incorrecto"); + return false; + } + + return true; +}