[Cialug] Javascript help
Kendall Bailey
krbailey at gmail.com
Fri Nov 4 19:13:13 CST 2005
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
>
More information about the Cialug
mailing list