View Single Post
Old 12-11-2012, 09:14 PM   PM User | #1
prash91
New Coder

 
Join Date: Oct 2012
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
prash91 is an unknown quantity at this point
Check Email validation and availablity.

Hi, I am trying to check email availability plus validation. I have a table called login, which has field email field init.
the availability part work perfectly in the code, which is done through small correct and wrong gif sign.however,I am not able to figure out how to use
emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; function.

I have following code,
index.php
Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="../style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).ready(function(){
$('#email').keyup(email_check);
});
	function email_check(){	
var email = $('#email').val();
 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 
        }



if(email == "" || email.length < 7){
$('#email').css('border', '3px #CCC solid');
$('#tick').hide();
}else{

jQuery.ajax({
   type: "POST",
   url: "check.php",
   data: 'email='+ email,
   cache: false,
   success: function(response){
if(response == 1){
	$('#email').css('border', '3px #C33 solid');	
	$('#tick').hide();
	$('#cross').fadeIn();
	}else{
	$('#email').css('border', '3px #090 solid');
	$('#cross').hide();
	$('#tick').fadeIn();
	     }

}
});
}
	
</script>

<style>
#email{
	padding:3px;
	font-size:18px;
	border:3px #CCC solid;
}

#tick{display:none}
#cross{display:none}
	

</style>
</head>

<body>

<div id="error"> </div>
Email: <input name="email" id="email" type="text" />
<img id="tick" src="tick.png" width="16" height="16"/>
<img id="cross" src="cross.png" width="16" height="16"/>




</body>
</html>
check.php
Code:
<?php
include("dbConnector.php");
$connector = new DbConnector();

$email = trim(strtolower($_POST['email']));
//$email = mysql_escape_string($email);


	$email = stripslashes($_POST['emal']);
	$email = strip_tags($email);
	$email = mysql_real_escape_string($email);

$query = "SELECT email FROM users WHERE email = '$email' LIMIT 1";
$result = $connector->query($query);
$num = mysql_num_rows($result);

echo $num;
mysql_close();

Last edited by prash91; 12-11-2012 at 09:21 PM..
prash91 is offline   Reply With Quote