Jump to content

Simple E-Mail Validation


CMellor

Recommended Posts

Hello,

I am stuck, as I am in the need for a very simple way to validate e-mail address' when a form has been submitted. My form is using AJAX to submit the form, and when a field is missed out, an alert() appears with the error. Here is my code for reference:

[code]function sendAppForm() {
// Error checking
// Display Name
if(document.app_form.display_name.value == "") {
alert("Please choose a superstar!");
document.app_form.display_name.focus();
return;
}
if(document.app_form.display_name.value.length < 3 || document.app_form.display_name.value.length > 32) {
alert("Your selected superstar has a too short or long name");
document.app_form.display_name.focus();
return;
}
// Username
if(document.app_form.username.value == "") {
alert("Please choose a username");
document.app_form.username.focus();
return;
}
if(document.app_form.username.value.length < 3 || document.app_form.username.value.length > 32) {
alert("Your selected username has a too short or long name");
document.app_form.username.focus();
return;
}
// Password
if(document.app_form.password.value == "") {
alert("Please choose a password");
document.app_form.password.focus();
return;
}
if(document.app_form.password.value.length < 3 || document.app_form.password.value.length > 32) {
alert("Your selected password has a too short or long name");
document.app_form.password.focus();
return;
}
// E-Mail

// Role Play
if(document.app_form.roleplay.value == "") {
alert("You MUST provide a Role Play!");
return;
}

ajax.open('POST', 'ajax/send_app.php');
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
document.getElementById("appForm").innerHTML = ajax.responseText;
}
};
ajax.send('superstar='+document.app_form.display_name.value);
}[/code]

I've tried a few bits of code, and they do actually validate the e-mail when it's not inserted correctly, but when it is and I try to submit the form, well it just won't submit.

Any help would be greatly appreciated!

Thanks!

Chris.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.