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.