473,405 Members | 2,272 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,405 software developers and data experts.

Form validation question

I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
I'm a total JavaScript newbie and am completely lost.

Thanks for reading!
Oct 22 '05 #1
16 2182
Hosh wrote on 22 okt 2005 in comp.lang.javascript:
I have a form on a webpage and want to use JavaScript validation for
the form fields.
I have searched the web for form validation scripts and have come up
with scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they
be joined in some way together to be one script?
..............
function validate(x){
// this depends on your requirements
firstInput = x.blah.value
................
}
</script>

............
<form onsubmit='return validate(this)'>
<input name='blah' ..........
I'm a total JavaScript newbie and am completely lost.


Learn or hire someone. Validating is not a beginners job.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #2
Thanks for that.
Learn or hire someone. Validating is not a beginners job. That's the plan (learn). That's why I'm here.
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.242... Hosh wrote on 22 okt 2005 in comp.lang.javascript:
I have a form on a webpage and want to use JavaScript validation for
the form fields.
I have searched the web for form validation scripts and have come up
with scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they
be joined in some way together to be one script?


.............
function validate(x){
// this depends on your requirements
firstInput = x.blah.value
................
}
</script>

...........
<form onsubmit='return validate(this)'>
<input name='blah' ..........
I'm a total JavaScript newbie and am completely lost.


Learn or hire someone. Validating is not a beginners job.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #3
Hosh wrote on 23 okt 2005 in comp.lang.javascript:
"Evertjan." <ex**************@interxnl.net> wrote in message
Hosh wrote on 22 okt 2005 in comp.lang.javascript:
I have a form on a webpage and want to use JavaScript validation for
the form fields.
I have searched the web for form validation scripts and have come up
with scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they
be joined in some way together to be one script?
.............
function validate(x){
// this depends on your requirements
firstInput = x.blah.value
................
}
</script>

...........
<form onsubmit='return validate(this)'>
<input name='blah' ..........
I'm a total JavaScript newbie and am completely lost.


Learn or hire someone. Validating is not a beginners job.


[first thing to learn: do not toppost on usenet, please]
Thanks for that.
Learn or hire someone. Validating is not a beginners job.

That's the plan (learn). That's why I'm here.


Then, we are not going to do your job in programming, doing sonone elses
programming is a professional job, but if you supply a bit of code you
are troubled with, you usually will get all the help you could wish.

As I showed you above, set your goals in validation and try to make some
code, test it in the framework I showed bove, or a better plan, I you
have one, and test it.

Then return with your problems.

Did you read this NG's FAQ and archive yet?

primary faq:
<http://jibbering.com/faq/>

secondary faq:
<http://www.merlyn.demon.co.uk/js-index.htm>

archive:
<http://groups.google.com/group/comp.lang.javascript>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #4
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.
Oct 23 '05 #5
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.


Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation
script for you, without you even trying, then yes you can to the wrong
newsgroup.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 23 '05 #6
"Hosh" <1@2.com> writes:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
Ok. First describe, in words, which values are acceptable for which
fields, and what should happen if the values fail to validate.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
It's dangerous to use other people's validation scripts without
understanding them, because they might not do exactly what you want.
E-mail validation is a case where many scripts you find are too
restrictive, and not accepting a user's e-mail is a pretty sure way
to lose a customer (if one's site has such). Likewise phone number
validation should probably be prepared for foreign numbers as well.
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
Most likely the latter. Each validation script consistes of some
scaffolding that calls the script at certain times, some actual
tests on values, and a response if validation fails. You only
want the scaffolding and response once, but you want a test
for each value that you have requirements for.
I'm a total JavaScript newbie and am completely lost.


Ok, here is a template for making a validation script:

---
<script type="text/javascript">
/* a validation function called when the user tries to submit the form */
function validate(form) {
var success = true;
// for each value to validate:
var field1Value = form.elements['field1'].value;
if (! ... some test on the value ...) {
success = false;
// possibly note which field fails for the user.
}
// end for each
if (!success) {
// tell the user somehow, e.g., alert("Invalid values entered")
// but preferably a more descriptive text.
}
return success;
}
</script>
.....
<form action=".." onsubmit="return validate(this);">
... <input type="text" name="field1" ... > ...
</form>

---

Such a validation script checks only when the user tries to submit.
It's also possible to validate a field as soon as the user leaves it
(or even when he presses a key, but that's usually considered too
intrusive), but what code you need depends on the description you
started out with of what it should do.
Also, never forget that client-side validation is only a convenience
to prevent a server round-trip that would fail anyway. The server must
always validate its input, whether the client does so or not.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 23 '05 #7

"Randy Webb" <Hi************@aol.com> wrote in message
news:_-********************@comcast.com...
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.


Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation script
for you, without you even trying, then yes you can to the wrong newsgroup.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

You know, in my original post, my only question was:
"Is it ok to put all these scripts on one page as they are or should they be
joined in some way together to be one script?"

I don't really see any request whatsoever for someone to write a damned
script for me!
You should wander into some friendly newsgroups and see how they treat
people that are just trying to get their feet wet.
Sorry for the intrusion!
Oct 23 '05 #8
Hosh said the following on 10/22/2005 9:23 PM:
"Randy Webb" <Hi************@aol.com> wrote in message
news:_-********************@comcast.com...
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.
Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation script
for you, without you even trying, then yes you can to the wrong newsgroup.


You know, in my original post, my only question was:
"Is it ok to put all these scripts on one page as they are or should they be
joined in some way together to be one script?"


Yes, you should combine them. But to be able to combine them you have to
have an understanding of what you are combining.
I don't really see any request whatsoever for someone to write a damned
script for me!
Fair enough.
You should wander into some friendly newsgroups and see how they treat
people that are just trying to get their feet wet.


You mean we aren't friendly? Awww shucks.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 23 '05 #9
Lee
Hosh said:


"Randy Webb" <Hi************@aol.com> wrote in message
news:_-********************@comcast.com...
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.


Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation script
for you, without you even trying, then yes you can to the wrong newsgroup.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

You know, in my original post, my only question was:
"Is it ok to put all these scripts on one page as they are or should they be
joined in some way together to be one script?"

I don't really see any request whatsoever for someone to write a damned
script for me!


Imagine somebody dropping by a forum of electrical contractors and
saying that they found some wires in their wall, and they wonder if
they should just connect them together.

You might get the impression that they're an unfriendly lot.
In the first place, we can't tell you if code that we've never seen
can be easily combined into a single validation function.

Then there's the whole problem of the trouble that you can get into
working with code that you don't understand.

Whether or not it's really dangerous depends on what sort of data
you're collecting, how you're transmitting it, and what you're doing
with it on the back-end.

Oct 23 '05 #10
Hosh wrote:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
I'm a total JavaScript newbie and am completely lost.

Thanks for reading!

First, Javascript form data validation is a misused term. You can make
sure submitted data is valid by utilizing client side technologies (i.e.
JavaScript). They can be fooled, disabled, bypassed, etc. Data
validation should be the job of the server side script.
Client side is useful in helping users fill the form, saving their time
and server bandwidth by pointing out errors and omissions. When both are
implemented properly, some functionality may overlap, but it will not be
all the same.

That said, google "fValidate"

--
Vladdy
http://www.klproductions.com
Oct 23 '05 #11

"Vladdy" <vl**@klproductions.com> wrote in message
news:SXC6f.2432$c4.1437@trndny03...
Hosh wrote:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
I'm a total JavaScript newbie and am completely lost.

Thanks for reading!

First, Javascript form data validation is a misused term. You can make
sure submitted data is valid by utilizing client side technologies (i.e.
JavaScript). They can be fooled, disabled, bypassed, etc. Data validation
should be the job of the server side script.
Client side is useful in helping users fill the form, saving their time
and server bandwidth by pointing out errors and omissions. When both are
implemented properly, some functionality may overlap, but it will not be
all the same.

That said, google "fValidate"

--
Vladdy
http://www.klproductions.com


Thanks.
I am aware of the potential problems with client-side validation, including
the fact that 10% of users have Javascript turned off in their browsers.
I do in fact have server-side data validation going on. I just wanted to
have some Javascript validation for exactly the reasons that you've outlined
above. The form I have is large and was hoping to alert the user to errors
as they went along as opposed to when they clicked the submit button.
Thanks again.
Oct 23 '05 #12
Hosh wrote:
[...]
I am aware of the potential problems with client-side validation,
including the fact that 10% of users have Javascript turned off in their
browsers.


Your numbers are -- as always with so-called statistics,
without reliable representative data to base on -- wrong.

And please learn how to quote properly: <http://jibbering.com/faq/>
PointedEars
Oct 23 '05 #13
Thomas 'PointedEars' Lahn said the following on 10/23/2005 4:50 AM:
Hosh wrote:

[...]
I am aware of the potential problems with client-side validation,
including the fact that 10% of users have Javascript turned off in their
browsers.

Your numbers are -- as always with so-called statistics,
without reliable representative data to base on -- wrong.


Do you have firsthand knowledge that he *doesnt* have "reliable
representative data" to base that 10% on? Unless you do, you can in *no
way* say it is wrong.
And please learn how to quote properly: <http://jibbering.com/faq/>


There was nothing wrong with the way Hosh quoted short of his news agent
not trimming the signature. But the quoting itself was fine.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 23 '05 #14
"Hosh" <1@2.com> writes:
The form I have is large and was hoping to alert the user to errors
as they went along as opposed to when they clicked the submit button.


In that case, what you want is not really "form validation" as much
as "field validation", since you validate each data field for itself.

It's more likely that you can combine several individual field
validation scripts on a page without changing them (as long as there
is no name collision) than that you could do the same for form
validations, since they are run independently.

A template for a single field validation would be something like:

---
<script type="text/javascript">
function validateSomeProperty(field) {
var value = field.value;
if (!... some test on value...) {
// report error, e.g.,
field.style.borderColor = "red";
// or : alert("Field foo contains invalid character"), or ...

// possibly fix entry (e.g., date into consisten format)
}
}
</script>
...
<form ...>
... <input type="text" name="email"
onchange="validateSomeProperty(this)"> ...
</form>
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 23 '05 #15
JRS: In article <SXC6f.2432$c4.1437@trndny03>, dated Sun, 23 Oct 2005
02:54:42, seen in news:comp.lang.javascript, Vladdy
<vl**@klproductions.com> posted :
First, Javascript form data validation is a misused term. You can make
sure submitted data is valid by utilizing client side technologies (i.e.
JavaScript). They can be fooled, disabled, bypassed, etc. Data
validation should be the job of the server side script.
Client side is useful in helping users fill the form, saving their time
and server bandwidth by pointing out errors and omissions. When both are
implemented properly, some functionality may overlap, but it will not be
all the same.

Don't presume that all processing is always carried out on the server,
or that any data is necessarily returned to the server. Javascript has
applications other than commercial.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 23 '05 #16
Dr John Stockton wrote on 23 okt 2005 in comp.lang.javascript:
JRS: In article <SXC6f.2432$c4.1437@trndny03>, dated Sun, 23 Oct 2005
02:54:42, seen in news:comp.lang.javascript, Vladdy
<vl**@klproductions.com> posted :
First, Javascript form data validation is a misused term. You can make
sure submitted data is valid by utilizing client side technologies (i.e.
JavaScript). They can be fooled, disabled, bypassed, etc. Data
validation should be the job of the server side script.
Client side is useful in helping users fill the form, saving their time
and server bandwidth by pointing out errors and omissions. When both are
implemented properly, some functionality may overlap, but it will not be
all the same.

Don't presume that all processing is always carried out on the server,
or that any data is necessarily returned to the server. Javascript has
applications other than commercial.


True.

If I want to do maintenance on my own on server databases from clientside
with a well password [and IP tested] protected page, clientside string
input validation is just as safe [and much faster].

"Hacking you own site" is a contradictio in terminis.
JRS: In article <SXC6f.2432$c4.1437@trndny03>, dated Sun, 23 Oct 2005
client side technologies (i.e. JavaScript).


Only partly. I use serverside javascript too.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 24 '05 #17

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

Similar topics

11
by: Jim | last post by:
Hi, I keep getting form results emailed to me that would indicate a form from my web site is getting submitted with all fields blank or empty, but my code should preventing users from proceeding...
6
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web...
6
by: Drew | last post by:
I've already created a simple method of ensuring that all form feilds are filled out before the form is submitted to an ASP page for records to be added to the data base. (Sorry about the...
2
by: Tim Mills | last post by:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a...
1
by: Colin Basterfield | last post by:
Hi, I have a web form which takes daily sales totals, both counts and monetary value and is done on a weekly basis, so on a Monday morning the User would enter these totals. Each total has a...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.