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>