I have form where I log in to access a restricted area of my website, but now I need to validate the typed e-mail, / em> that I currently have and could not perform validation.
What I have 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 does the login validation:
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.');
}