I am doing new tests in a separate project, either to finish one that I do along with the course or to see if I am learning 100% of the material in this course, however, in a simple example there is something that does not come out.
test file -> javascript.php
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><!-- /*TEMPORAL PARA EL MENÚ NUEVO O VIEJO*/ -->
<meta name="author" content="José Carlos" />
<meta name="description" content="Practicas y proyectos realizados en php, POO, MVC, javascript, html5, css3" />
<meta name="keywords" content="proyectos, realizados, php, POO, MVC, javascript, html5, css3" />
<title>Plantilla de Mis proyectos en PHP</title>
<link rel="stylesheet" href="http://localhost/mis-proyectos-php/vistas/js/usuarios.jsvistas/css/principal.css">
</head>
<body>
<!-- <form method="post" action="algo.php" onsubmit="return registroUsuario()" class="form-login-registro"> -->
<form method="post" onsubmit="return registroUsuario()" class="form-login-registro">
<div id="alertaPrueba"> <!-- Temporal para la respuesta javascript -->
<span class="form-login-registro">* EMAIL:</span>
<input type="text" name="regEmail" size="30" maxlength="50" placeholder="E-mail" class="input-login-registro input text" id="regEmail" /> <!-- Cambiado temporalmente a type=text para hacer pruebas de javascript -->
</div>
<span class="button-form-registro"><input type="submit" value="REGISTER" class="input submit" /></span>
</form>
<script src="http://localhost/mis-proyectos-php/vistas/js/usuarios.js"></script>
</body>
</html>
javascript file -> users.js
/*=============================================
VALIDAR EL REGISTRO DE USUARIO
=============================================*/
function registroUsuario(){
/*=============================================
VALIDAR EL EMAIL
=============================================*/
var email = $("#regEmail").val();
if(email != ""){
var expresion = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
if(!expresion.test(email)){
$("#regEmail").parent().before('<div class="alert alert-warning"><strong>ERROR:</strong> Escriba correctamente el correo electrónico</div>')
return false;
}
}else{
$("#regEmail").parent().before('<div class="alert alert-warning"><strong>ATENCIÓN:</strong> Campo obligatorio: email.</div>')
return false;
}
return true;
}
What am I doing wrong? It does not recognize the empty field nor the error of putting the wrong email.
Greetings.
I just edited it and it works perfectly by adding this part to the code.
Thank you both for your help.