1
I own a form where I perform login to access a restricted area of my site, but now I need to validate the typed email, I tried to change the script that I currently have and have not been able to perform the validation.
What I got is this:
<!-- language: lang-js -->
$(document).ready(function(){
$('#MsgErro').hide();
$('#formLogin').submit(function(){
var login = $('#email').val();
var senha = $('#senha').val();
$.ajax({
url:"login.php",
type:"post",
data: "login="+login+"&senha="+senha,
success: function (result){
if (result == 1) {
location.href = 'restrito.php'
} else {
$('#MsgErro').show();
}
}
})
return false;
})
})
The PHP
that validates the login:
mysql_connect('***', '***','***')or die();
mysql_select_db('***');
$login = mysql_real_escape_string($_POST['login']);
$senha = mysql_real_escape_string($_POST['senha']);
$sql = "SELECT * FROM usuarios_catalogos WHERE email='".$login."' AND senha='".md5($senha)."'";
$resultados = mysql_query($sql) or die (mysql_error());
$res = mysql_fetch_array($resultados); //
if (@mysql_num_rows($resultados) == 0){
echo 0;
} else {
echo 1;
if (!isset($_SESSION))
session_start();
$_SESSION['usuarioID'] = $res['id'];
$_SESSION['nomeUsuario'] = $res['nome'];
$_SESSION['email'] = $res['email'];
exit;
}
Error message:
<h4 style=" font-family: 'Open Sans Condensed', sans-serif; font-size: 16px;" align="center" id="MsgErro">Usuário ou senha informados incorretamente</h4>
And what I tried to do was this:
var emailFilter=/^.+@.+\..{2,}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
// condição
if(!(emailFilter.test(email))||email.match(illegalChars)){
$("MsgErro").show()
.text('Por favor, informe um email válido.');
}