^\d*(\.\d{1,2})?$

This should do it if you allow an empty string to be validated as a
number. If you don't allow empty strings, just test that the length is
greater than zero. This would be easier than writing the regexp to test
for that too.

Pascal

> -----Original Message-----
> From: DURETTE, STEVEN J (AIT) [mailto:[EMAIL PROTECTED]
> Sent: 10 January 2005 20:43
> To: CF-Talk
> Subject: Regex Help.
> 
> Hi All,
> 
> Need some help with a regex.  What I'm trying to do is validate and
> input in javascript.
> 
> The users are allowed to input a number.
> 
> It can be in the following formats:
> 9
> 9.9
> 9.99
> .99
> .9
> 
> (9 used inplace of any digit.)
> 
> I tried using \b[0-9.]+  and I've tried \b[\d]*([.]?[\d]{0,2})? and
I've
> tried  ([\d]*([.][\d]{1,2})?){1} but I can't seem to get the response
> that I want.
> 
> The user can still input numbers such as 1.25.25 and it will pass the
> regex test.
> 
> To be more specific in what I'm looking for, the users are putting in
> hours and partial hours.
> There can be any amount of hours, but partial hours are limited to .0,
> .00,.25, .5, .50, .75 or no decimal part whatsoever. (I've been trying
> to do the .25, .5, etc in another part of the javascript, but if I can
> do it in the regex even better.)
> 
> Anybody got any ideas.
> 
> Thanks
> Steve
> 
> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Protect your mail server with built in anti-virus protection. It's not only 
good for you, it's good for everybody.
http://www.houseoffusion.com/banners/view.cfm?bannerid=39

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:189886
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to