MDIS/src/validate_user.js

64 lines
1.4 KiB
JavaScript

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;
}
function validateLogin(){
var user = document.forms["login_form"]["usuario"];
var password = document.forms["login_form"]["contraseña"];
if(!validateString(user.value)){
alert("Introduce el usuario");
return false;
}
if(!validateString(password.value)){
alert("Introduce la contraseña");
return false;
}
return true;
}