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

for loop for unknown number of fields to validate

I must confirm the user enters a value for each fund they need. I do not know
how many fund entries there will be...it's expandable to handle each users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am using
it for other things).

My problem is with my validate function which I've cut down (oh it doesn't
work but you can see the direction I am going with it). Is there a better way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow;i++) {
If (eval("!Is_In_Format( document.forms[0].fund_" + i + ".value, "dddddd")
|| document.forms[0].fund_" + i + ".value.length != 6")){
alert("Fund must be 6 digits");
eval("document.forms[0].fund_" + i + ".focus();")
}
}
Jul 23 '05 #1
6 2143
Abby Lee wrote:
I must confirm the user enters a value for each fund they need. I do not know
how many fund entries there will be...it's expandable to handle each users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am using
it for other things).

My problem is with my validate function which I've cut down (oh it doesn't
work but you can see the direction I am going with it). Is there a better way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow;i++) {
If (eval("!Is_In_Format( document.forms[0].fund_" + i + ".value, "dddddd")
|| document.forms[0].fund_" + i + ".value.length != 6")){
alert("Fund must be 6 digits");
eval("document.forms[0].fund_" + i + ".focus();")
}
}

function validate(){
f-document.forms[0];
for(i=1;i<=nrow;i++) {
if(f["fund"+i].value){
if(!/^\d{6}$/.test(f["fund"+i].value){
alert("Fund must be 6 digits");
f["fund_" + i].focus();
return false;
}
}
}
return true;
}

I am assuming empty fields are OK.
Mick
Jul 23 '05 #2
Mick White <mw******@rochester.rr.com> writes:
Abby Lee wrote:
I must confirm the user enters a value for each fund they need. I do not
know
how many fund entries there will be...it's expandable to handle each
users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am
using
it for other things).

My problem is with my validate function which I've cut down (oh it
doesn't
work but you can see the direction I am going with it). Is there a better
way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow;i++) {
If (eval("!Is_In_Format( document.forms[0].fund_" + i + ".value,
"dddddd")
|| document.forms[0].fund_" + i + ".value.length != 6")){
alert("Fund must be 6 digits");
eval("document.forms[0].fund_" + i + ".focus();")
}
}

function validate(){
f-document.forms[0];
for(i=1;i<=nrow;i++) {
if(f["fund"+i].value){
if(!/^\d{6}$/.test(f["fund"+i].value){
alert("Fund must be 6 digits");
f["fund_" + i].focus();
return false;
}
}
}
return true;
}

I am assuming empty fields are OK.
Mick


Mick,
Can you explain what you are doing here...I could not get it to work, even
after changing it to check just the one "fund" field they must use.

function validate(){
if(!/^\d{6}$/.test(document.forms[0].fund_1.value){
alert("Fund must be 6 digits");
document.forms[0].fund_1.focus();
}
else document.forms[0].submit();
}
Jul 23 '05 #3
Abby Lee <ab*******@hotmail.com> writes:
Mick White <mw******@rochester.rr.com> writes:
Abby Lee wrote:
I must confirm the user enters a value for each fund they need. I do
not
know
how many fund entries there will be...it's expandable to handle each
users
needs. I must varify each fund they enter is six digits long. I have no

problems with the Is_In_Format function (I found it on the web and am
using
it for other things).

My problem is with my validate function which I've cut down (oh it
doesn't
work but you can see the direction I am going with it). Is there a
better
way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow;i++) {
If (eval("!Is_In_Format( document.forms[0].fund_" + i + ".value,
"dddddd")
|| document.forms[0].fund_" + i + ".value.length != 6")){
alert("Fund must be 6 digits");
eval("document.forms[0].fund_" + i + ".focus();")
}
}

function validate(){
f-document.forms[0];
for(i=1;i<=nrow;i++) {
if(f["fund"+i].value){
if(!/^\d{6}$/.test(f["fund"+i].value){
alert("Fund must be 6 digits");
f["fund_" + i].focus();
return false;
}
}
}
return true;
}

I am assuming empty fields are OK.
Mick


Mick,
Can you explain what you are doing here...I could not get it to work, even
after changing it to check just the one "fund" field they must use.

function validate(){
if(!/^\d{6}$/.test(document.forms[0].fund_1.value){
alert("Fund must be 6 digits");
document.forms[0].fund_1.focus();
}
else document.forms[0].submit();
}

Nevermind and thank you Mick, I got it working ;)
Jul 23 '05 #4
JRS: In article <ui***************************@news.ks.uiuc.edu> , seen
in news:comp.lang.javascript, Abby Lee <ab*******@hotmail.com> posted at
Mon, 26 Apr 2004 11:08:04 :
I must confirm the user enters a value for each fund they need. I do not know
how many fund entries there will be...it's expandable to handle each users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am using
it for other things).

My problem is with my validate function which I've cut down (oh it doesn't
work but you can see the direction I am going with it). Is there a better way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow;i++) {
If (eval("!Is_In_Format( document.forms[0].fund_" + i + ".value, "dddddd")
|| document.forms[0].fund_" + i + ".value.length != 6")){
alert("Fund must be 6 digits");
eval("document.forms[0].fund_" + i + ".focus();")
}
}


Rather than using some dubious function from the Web, why not test
directly with a RegExp /$\d{6}$/ ?

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#VFF> has a general
method, shown in ...#TC, using an Array in an Object to define all the
tests on a form; it should be possible to replace the scanning of the
array with scanning what I suppose to be an array of elements.

You want something like

function validate() { var F, OK
for(i=0;i<nrow;i++) { F = document.forms[0].element[i] // or similar
OK = /$\d{6}$/.test(F.value) // 6 digits only
if (!OK) { alert("Fund " + i + " must be 6 digits") ; F.focus() ;
return false } }
return true }

FAQ 4.40, 4.39, of course.

--
© 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> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
Dr John Stockton wrote:

<snip>

function validate() { var F, OK
for(i=0;i<nrow;i++) { F = document.forms[0].element[i] // or similar
OK = /$\d{6}$/.test(F.value) // 6 digits only
if (!OK) { alert("Fund " + i + " must be 6 digits") ; F.focus() ;
return false } }
return true }

FAQ 4.40, 4.39, of course.

OP states that empty fields are OK. But if there is an entry, it should
be 6 digits.
See my earlier posting.
Mick
Jul 23 '05 #6
JRS: In article <zV********************@twister.nyroc.rr.com>, seen in
news:comp.lang.javascript, Mick White <mw******@rochester.rr.com> posted
at Mon, 26 Apr 2004 23:27:27 :
Dr John Stockton wrote:

<snip>

function validate() { var F, OK
for(i=0;i<nrow;i++) { F = document.forms[0].element[i] // or similar
OK = /$\d{6}$/.test(F.value) // 6 digits only
if (!OK) { alert("Fund " + i + " must be 6 digits") ; F.focus() ;
return false } }
return true }

FAQ 4.40, 4.39, of course.

OP states that empty fields are OK. But if there is an entry, it should
be 6 digits.


(a) The first $ above should be ^
(b) OK = /^$|^\d{6}$/.test( ) // seems OK; empty or 6-digit

--
© 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> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7

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

Similar topics

2
by: Bartosz Wegrzyn | last post by:
I use onblue event to validate fields in my form. I do this onblur="return isname()" and so so ... I have one form with 20 fields. My problem is that when the focus is for example on the...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
6
by: simina | last post by:
Hi... I have a form with 4 number fields: phone area, phone number, cell area, cell number. I did a function that checks the "number" issue for all 4 fields in the same time (because the code is...
8
by: Abby Lee | last post by:
My function works but there has got to be a way to make a for loop to handle this...but I can't get a for loop to work. You can tell, I'm not very good at this...help. "myvalue" is the number of...
4
by: just.an.imbecile | last post by:
I have searched alot for this and cannot find an answer. I have a simple form, and when it submits, I have it posting the data. I have a simple function to loop through and print out all my form...
5
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab...
4
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into...
5
by: imailz | last post by:
Hi all, since I'm forced to switch from Fortran to C I wonder if there is posibility in C: 1) to use implicit loops 2) to parse several variables which number is determined at runtime. ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...

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.