0

Hi,
I am new in jquery.
I am working on a registration page.I did all the validation but facing problem during username validation.
when a user enter email id in the textbox,it first check whether it is present in database or not..
if not present "register successfully" otherwise "email exists"
Need suggestions

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
};
$(".submit").click(function() {


    var name = $("#name").val();
	var username = $("#username").val();
	var password = $("#password").val();
	var type = $("#type").val();
	var mobile=	$("#mobile").val();
	var city=$("#city").val();
	var rpassword=$("#rpassword").val();
    var dataString = 'name='+ name + '&username=' + username + '&password=' + password + '&rpassword=' + rpassword+ '&type=' + type + '&mobile=' + mobile + '&city=' + city;
	if(name=='' || username=='' || password=='' || rpassword=='' || type=='' || city=='' || mobile=='')
	{
	$('.success').fadeOut(200).hide();
    $('.error').fadeOut(200).show();
    $('.pwd_error').fadeOut(200).hide();
    $('.error1').fadeOut(200).hide();
	}
	
	else if( !isValidEmailAddress(username) ) 
	  { 
	   $('.success').fadeOut(200).hide();
       $('.error').fadeOut(200).hide();
       $('.error1').fadeOut(200).show();
       $('.pwd_error').fadeOut(200).hide();
	  }
	  
	else if(!(password==rpassword))
	{
	 $('.success').fadeOut(200).hide();
     $('.error').fadeOut(200).hide();
     $('.pwd_error').fadeOut(200).show();
     $('.error1').fadeOut(200).hide();
	}
	else
	{
	$.ajax({
	type:"POST",
    url:"http://localhost/reg/join.php",
    data:dataString,
    success: function(){
	$('.success').fadeIn(200).show();
    $('.error').fadeOut(200).hide();
    $('.pwd_error').fadeOut(200).hide();
    $('.error1').fadeOut(200).hide();

    $('#name').val('');
    $('#type').val('');
    $('#password').val('');
    $('#rpassword').val('');
    $('#username').val('');
    $('#mobile').val('');
    $('#city').val('');
		
   }
});

	}
		
    return false;
	});

});
</script>
2
Contributors
1
Reply
9
Views
6 Years
Discussion Span
Last Post by Agarsia
0

Use ajax.
to test if username already exists add this to your jquery:

$.post('checkusername.php',{'username':username},function(data) {
 if(data=="0") {
  //Username does not exist
 } else {
  //Username already exists
 }
});

and create the checkusername.php:

echo mysql_num_rows(mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'"));

I hope it helps you to solve your problem.

-Agarsia

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.