473,549 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript"> //This defines the language as javascript
<!-- hide JS code
function validateForm(fo rm)

{
// EMAIL VALIDATION

if (!validateEMail (form.Email.val ue)) // is the email address valid?
{
form.Email.focu s()
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(E mail)
{
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: dummyemailaddre ss.co.uk" method="post"
onSubmit="justV alidating=false ; return validateForm(Va lidate)">

<input type="text" name="Email">
<input type="submit" name="Submit" value="Submit" ; validateForm(Va lidate)>

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


Any help appreciated

Thanks

Andrew

Jul 20 '05 #1
2 3390
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="JavaS cript"> //This defines the language as javascript
You are missing the required type attribute.

<URL:http://www.w3.org/TR/html401/interact/scripts.html#ed ef-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(E mail)
{ [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_addr esses.php>
[snip] <form name="Validate" action="mailto: dummyemailaddre ss.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(Va lidate)>
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.or g/>.

--
Jim Dabell

Jul 20 '05 #2
JRS: In article <OL************ ********@newsfe p4-glfd.server.ntl i.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.demo n.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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.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
10410
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 Error GoTo EENUMErr If IsNull(Me.EmployeesID) Or Me.EmployeesID = "" Or Me.EmployeesID < 0 Then MsgBox "Employee Number Cannot Be Left Blank",...
2
2679
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 of my fields. I have a table called "Product" and two of the fields included in this table are "Cost Price" and "Retail Price". I need to create a...
7
736
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 characters and ONLY NUMBERS should be inputted. Does anyone know what the validation rule should be for this field?
4
2707
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 If the message contains the word porn, can I block the whole message using a validation rule
10
5695
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 form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to...
2
4023
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 in the validation rule field: Like "*.0" Or Like "*.25" Or Like "*.5" Or Like "*.75" but it isn't working. When I enter 1.0, I would think that...
7
5959
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 (that is selected via a drop down list). Example Field1 - options are "In" or "Out" Field2 - options are "Join" or "Not Joining"
1
2073
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 in which the append fails and the reported error is validation rule. The table being appended to (tblClusters) has only 1 field with a...
18
6204
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 message box is displayed with: ----------- myApplication (i bubble icon) The value violates the validation rule for the field or record. For...
4
8209
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 that are connect to it and it works as it should.. What I wanna to do it in some special case I wan to test tb.Text.Equals("myTestStr") or if the...
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.