473,748 Members | 6,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2248
Hosh wrote on 22 okt 2005 in comp.lang.javas cript:
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='retur n 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******** ************@19 4.109.133.242.. . Hosh wrote on 22 okt 2005 in comp.lang.javas cript:
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='retur n 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.javas cript:
"Evertjan." <ex************ **@interxnl.net > wrote in message
Hosh wrote on 22 okt 2005 in comp.lang.javas cript:
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='retur n 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.demo n.co.uk/js-index.htm>

archive:
<http://groups.google.c om/group/comp.lang.javas cript>
--
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.javas cript 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="retur n 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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 23 '05 #7

"Randy Webb" <Hi************ @aol.com> wrote in message
news:_-*************** *****@comcast.c om...
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.javas cript 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.c om...
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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 23 '05 #9
Lee
Hosh said:


"Randy Webb" <Hi************ @aol.com> wrote in message
news:_-*************** *****@comcast.c om...
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.javas cript 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

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

Similar topics

11
8755
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 if they left any field blank. My guess is that someone is trying to hack the site using the form to gain entry or run commands -- I don't really know since I'm not a hacker. I just know that forms are often susceptible to these kinds of...
6
4340
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 developers, but is relevant discussion. i'm not OT here unless someone thinks i'm trolling (which i'm not, obviously). then i'll disappear and never show my face again. :P
6
1936
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 formating, my newsreader may make it a mess!) <script language="javascript"> <!-- function Check(form) {
2
2367
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 message to tell the user if all the fields have been fill-out. If the user has missed some information the form re-displays with red "alerts" indicating where the user have missed the information while re-populating the information the user has...
1
1630
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 range, which at the lower end is >= 0 and the upper limit is configurable, these totals are then submitted to a web service which posts them to a data store. The question is regarding validation, obviously I can validate on the web form using...
9
4179
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
27
4752
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
11
3000
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
18
5808
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 script code being executed having a flaw: function anonymous() { if (!ValidatedTextBoxOnKeyPress(event)) { event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); return false; } }
0
8989
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4599
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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
2
2780
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.