I found a registration script that queries a database to see if a username is available. I want to change it to see if an email is available. I was able to change it to check for email from the database, however, I need to add a function or a jquery call to verify that the email has proper syntax (require “@” and “.”). The issue is that its checking the email from the database, but even if you type a non valid email like “adfasdfasdf” it will come back with a checkmark, even though its not a proper email format. So this is what Im trying to fix…
Here is the example of the username script
http://papermashup.com/demos/check-username
And here is my version of the same script, but I changed all the variables to be email instead of username (and it works). And I think I found the right spot to put the email validation, but not too sure. See “&& isValid(email)” halfway through the script below:
function email_check(){
var email = $('#my_email').val();
if(email == "" || email.length < 8){
$('#my_email').css('border', '1px #CCC solid');
$('#tick').hide();
} else {
jQuery.ajax({
type: "POST",
url: "ajax-email-validate.php",
data: 'email='+ email,
cache: false,
success: function(response){
if(response == 1 && isValid(email) ){
$('#my_email').css('border', '1px #C33 solid');
$('#tick').hide();
$('#cross').fadeIn();
} else {
$('#my_email').css('border', '1px #090 solid');
$('#cross').hide();
$('#tick').fadeIn();
}
}
});
}
}
Is “&& isValid(email)” the correct spot to check if the email is valid? Should I write a javascript function to check for @ and . or is there a jQuery way? I know there has to be…
thanks for any suggestions!