Validation rule not working

A

Andrew

I've ripped off some script from another site of mine that works fine which
checks an input box to see if an email address has been entered when
submitting. If it hasn't a prompt is issued asking the user to enter an
email address.

It seems to be ignoring the validation rule and just emailing the form
anyway, can anyone help?

Below is the the relevant code -



From the <head> tag-

<SCRIPT LANGUAGE="JavaScript"> //This defines the language as javascript
<!-- hide JS code
function validateForm(form)

{
// EMAIL VALIDATION

if (!validateEMail(form.Email.value)) // is the email address valid?
{
form.Email.focus()
return false
}



if (justValidating=true) // the alert box only shows when validating, not
submitting
alert("Thank you. Your data has been validated and is ready to be
submitted.") // message shown if all data is valid
return true
}

// EMAIL VALIDATION RULES

function validateEMail(Email)
{
if (isBlank(Email)) // email blank?
{
alert("Enter your email address, please!") // return this message if it is
blank
return false
}
var atsignPos = Email.indexOf("@", 0) // check for @ sign
if (atsignPos == -1)
{
alert("Enter a valid email address with an @, please!") // return this
message if no @ sign present
return false
}
if (Email.indexOf(".", atsignPos) == -1) // check for full stop after @ sign
{
alert("Enter a valid email domain after the @, please!") //return this
message if no full stop after @ sign
return false
}
return true
}





// end JS hide -->
</SCRIPT>



And then this is the details within the form -

<form name="Validate" action="mailto:dummyemailaddress.co.uk" method="post"
onSubmit="justValidating=false; return validateForm(Validate)">

<input type="text" name="Email">


<input type="submit" name="Submit" value="Submit" ; validateForm(Validate)>

<input type="reset" name="Reset" value="Reset"></form>






Any help appreciated

Thanks

Andrew
 
D

Dr John Stockton

JRS: In article <OL8%[email protected]>,
seen in Andrew <andrew-
(e-mail address removed)> posted at Fri, 15 Aug 2003 18:31:01 :-
I've ripped off some script from another site of mine that works fine which
checks an input box to see if an email address has been entered when
submitting. If it hasn't a prompt is issued asking the user to enter an
email address.

It seems to be ignoring the validation rule and just emailing the form
anyway, can anyone help?

if (justValidating=true) // the alert box only shows when validating, not ==
xxxxx
submitting
alert("Thank you. Your data has been validated and is ready to be
submitted.") // message shown if all data is valid

That's another reason for never testing equality with a Boolean
constant; the better fix is on the second inserted line.

One can do a little better testing E-addresses; use a RegExp to test for
something at something dot something

See in <URL:http://www.merlyn.demon.co.uk/js-other.htm#VEmA>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top