473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Validation rule not working

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

Jul 20 '05 #1
2 3365
Andrew wrote:

[snip]
It seems to be ignoring the validation rule and just emailing the form
anyway, can anyone help? [snip] From the <head> tag-
The <head> element - the code certainly doesn't reside within the tag.

<SCRIPT LANGUAGE="JavaScript"> //This defines the language as javascript
You are missing the required type attribute.

<URL:http://www.w3.org/TR/html401/interact/scripts.html#edef-SCRIPT>

<!-- hide JS code
Practically speaking, this does nothing, except increase the possibility for
headaches if you plan to use XHTML in the future. In any case, it's
usually a better idea to put your Javascript in external files.
[snip] if (justValidating=true) // the alert box only shows when validating, not
submitting
I fail to see the difference. Your form as described is only ever validated
when it is submitted.

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)
{ [snip]

That is fairly convoluted code that gives false positives and false
negatives. Why not just use a couple of regexps instead? There is some
discussion of the issues here:

<URL:http://blog.tom.me.uk/2003/08/03/evil_email_addresses.php>
[snip] <form name="Validate" action="mailto:dummyemailaddress.co.uk"
mailto actions are unreliable.

<URL:http://www.netmechanic.com/news/vol3/form_no4.htm>
[snip] <input type="submit" name="Submit" value="Submit" ;
validateForm(Validate)>
This isn't valid HTML, there is no Javascript seen by the browser here. The
onsubmit attribute of the <form> element takes care of the validation when
the form is submitted anyway.

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


<URL:http://www.useit.com/alertbox/20000416.html>
Good places to look for hints when debugging are the Javascript console in
Mozilla, and the HTML validator service at <URL:http://validator.w3.org/>.

--
Jim Dabell

Jul 20 '05 #2
JRS: In article <OL********************@newsfep4-glfd.server.ntli.net>,
seen in news:comp.lang.javascript, Andrew <andrew-
di**************@ntlworld.com> 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 ==
xxxxxsubmitting
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>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Doslil | last post by:
I am trying to validate the fields in my database.I have already validated the fields to check for not null.Here is what I have written for Numeric and text field. Private Function EENUM() On...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
7
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help? I have a field in a table called: ADMIN NUMBER This field should have 4...
4
by: ron | last post by:
I have a access based guest book. I want to create a validation rule to block certain words or parts of a srting. How do i do this? ie: this is a nice site. come visit my porn site at www.abc.zy...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
2
by: ckpoll2 | last post by:
Hello, I'm trying to set a validation rule for a field in a table that will only allow the user to enter whole hours or quarter hour increments, like 1 or 2.25. I'm using the following statement...
7
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer...
1
by: MLH | last post by:
Anyone remember if A97 append query failure would ever report data breaking validation rule when such was not the case. I have an old SQL statement - several years old now. I've encountered a case...
18
by: ChipR | last post by:
I have a text box with a validation rule and validation text. When entering a new record, if I put in invalid text, the validation text is displayed in a message box, but after clicking OK, another...
4
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.