I use the following (shorten version) function to validate and proccess a registration form:
function submit_registration(){
var reg = /^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$/;
var name = $("#name").val();
var email = $("#email").val();
if(name == "")
{
$("#send_status").html('<div class="error">Fill in your name to continue.</div>');
$("#name").focus();
}
else if(email == "")
{
$("#send_status").html('<div class="error">Fill in your e-mail address to continue.</div>');
$("#email").focus();
}
else if(reg.test(email) == false)
{
$("#send_status").html('<div class="error">This is not a valid e-mail address.</div>');
$("#regemail").focus();
}
else
{
var dataString = 'name='+ name + '&email='+ email;
$.ajax({
type: "POST",
url: "modules/site/process_registration.php",
data: dataString,
cache: false,
beforeSend: function()
{
$("#send_status").html('<div class="sending">Please wait...</div><br "class="clear">');
},
success: function(response)
{
$("#send_status").html($(response).fadeIn(2000));
$("#reg_form").fadeOut(1000);
$("#name").val('');
$("#email").val('');
}
});
}
}
What I need is a way to check if the given email address is already in the database. Is that possible within this function and if yes how? Or should I approach this in a different way?
Thank you in advance.