[Cialug] Javascript help

Kevin C. Smith kevin at linuxsmith.com
Fri Nov 4 23:24:17 CST 2005


I got it working now. I thought about dropdowns; I have them for other 
fields, I may still. I don't know if I want to require their use 
and still would want to do some checking of the fields though. 

On Fri, 2005-11-04 at 23:10 -0600, Dave Weis wrote:
> Sorry for being dense but just use a couple dropdowns, one 0-23 and one 
> with 00 15 30 45.
> 
> On Fri, 4 Nov 2005, Kevin C. Smith wrote:
> 
> > I thought the same thing, and think I tried exactly what you suggest
> > but something didn't work right. I forget exactly. So, I went and go
> > funky trying to get it to work. I will revisit this and see if I just
> > missed something.
> >
> >> I don't do javascript, but with such a small number of acceptable
> >> fractions, why not just enumerate them?
> >>
> >> pattern = /^[0-9]*\.(0|00|25|5|50|75)$/;
> >>
> >> Why all the square brackets?  Does the javascript regexes need them?
> >>
> >> Kendall
> >>
> >>
> >> On 11/4/05, Kevin C. Smith <kevin at linuxsmith.com> wrote:
> >>> This is by first attempt at this, so be easy on me.
> >>>
> >>> I'm trying to come up with a javascript function to check an html form
> >>> input field. I've got most of it but I'm have trouble with the number
> >>> after
> >>> the ".". I'm trying to match number in the form of 12.0, 12.5, 12.00,
> >>> 12.25, 12.50, 12.75 for example. I've got the following:
> >>>
> >>> pattern = /^[0-9]*\.[0][0]{1}$|[2][5]{1}$|[5][0]{1}$|[7][5]{1}$/;
> >>>
> >>> which matches 12.00, 12.25, 12.50, 12.75 (example), but when I attempt
> >>> to
> >>> also
> >>> match 12.0 or 12.5 I open the door to 12.255555 which I don't want.
> >>>
> >>> I've also noticed the it accecpt stuff like "2,5.25" which I also don't
> >>> want.
> >>>
> >>> So far I have this:
> >>>
> >>> <script type="text/javascript">
> >>> function        checknumber(field,limit)
> >>> {
> >>>         pattern =
> >>> /^[0-9]*\.[0][0]{1}$|[2][5]{1}$|[5][0]{1}$|[7][5]{1}$/;
> >>>         if(pattern.test(field.value)==false)
> >>>         {
> >>>                 alert("Please use proper format - 1:15 PM is 13.25");
> >>>                 field.value = 0;
> >>>         }
> >>>         else
> >>>         {
> >>>                 if(field.value > limit)
> >>>                 {
> >>>                         alert("Out of Range! The range is 0.25-24.0");
> >>>                         field.value = 0;
> >>>                 }
> >>>         }
> >>> }
> >>> </script>
> >>>
> >>> Any help would be great.
> >>> Thanks,
> >>>
> >>> --
> >>> Kevin C. Smith
> >>>
> >>> _______________________________________________
> >>> Cialug mailing list
> >>> Cialug at cialug.org
> >>> http://cialug.org/mailman/listinfo/cialug
> >>>
> >> _______________________________________________
> >> Cialug mailing list
> >> Cialug at cialug.org
> >> http://cialug.org/mailman/listinfo/cialug
> >>
> >>
> >>
> >
> >
> >
> 
-- 
Kevin C. Smith

"In the first place God made idiots. This was for practice. Then he made
Members of Congress." -- Mark Twain



More information about the Cialug mailing list