Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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 10:21 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
        return emailReg.test(email);
    will return true or false from your function email_check().
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have change the code to following as per your suggestion.however,It doesn't work, even the availability part has stop working after inserting ,

    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    return emailReg.test(email);.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <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})?$/;
    return emailReg.test(email);
    
    if(email == "" || email.length < 4){
    $('#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>
    
    
    
    
    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>
    Last edited by prash91; 12-14-2012 at 01:20 AM.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Yes, of course it wont work; you've just thrown my code sample into your function . Because it is at the top of your function email_check() it will cause an immediate return (not executing any of the code that follows it) and the value of true or false that it returns will just be discarded, as you don't do anything with it.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Please give me the solution how it will work.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •