PDA

View Full Version : Error trapping x@x.xxx in form


jonathen
07-09-03, 05:04 AM
Hi all,

I have a javascript function I use for ensuring that the person filling in my form fills out each of the fields. This works well, but there is another feature I would like to add to it, but do not know what the syntax is, nor how I would be able to incorporate it into my current script without breaking it. I would like to ensure that not only does the person fill out all fields, including the email address field, but that if he/she was to fill out the email field with n/a or something that is not x@x.xxx (in other words a valid email string), it returns an alert alike to the ones I already use (in this case, telling the user to enter a real email address)

Any help is appreciated :)

This is my current script:

<!--
function checkform ( form )
{

// ** START **
if (form.name.value == "") {
alert( "Please enter your full name." );
form.name.focus();
return false ;
}
// ** END **
// ** START **
if (form.address.value == "") {
alert( "Please enter your full address." );
form.address.focus();
return false ;
}
// ** END **
// ** START **
if (form.postcode.value == "") {
alert( "Please enter your postcode." );
form.postcode.focus();
return false ;
}
// ** END **
// ** START **
if (form.phone.value == "") {
alert( "Please enter your phone number, including area code." );
form.phone.focus();
return false ;
}
// ** END **
// ** START **
if (form.emailaddr.value == "") {
alert( "Please enter your correct email address." );
form.emailaddr.focus();
return false ;
}
// ** END **
return true ;
}
//-->

jonathen
07-11-03, 04:02 AM
Don't worry about it - I found the answer and got it working.