[thelist] regex help

Joshua Olson joshua at waetech.com
Mon Sep 20 09:45:36 CDT 2004

> -----Original Message-----
> From: Theodore Serbinski
> Sent: Monday, September 20, 2004 10:36 AM
> hey all! i'm working on form validation for numerical timesheet values
> but i can't seem to get the regex right to test the values. what i have
> right now is:
> 	/^([012]?[0-9]\.[0-9])?$/
> i'm trying to test for all values in this range:
> 	0.0 - 24.0
> with these stipulations:
> 	- an empty string is ok, treated as 0 by the script anyways
> 	- only one decimal place allowed, which is optional
> any help is appreciated, i'm still really new at these regexes. thanks!


Very good work.  You are almost there.  The only piece that I would change
would be to make a condition roughly meaning "IF there is a decimal, ensure
there is at least one digit, IF NOT, nothing should follow".  The following
rule means just that:

(\.[0-9])?   Literally: "a period followed by a single character 0-9, or

So, here's what you had, but incorporating the new logic:


Best of luck,

Joshua Olson
Web Application Engineer
WAE Tech Inc.

More information about the thelist mailing list