You are here: Re: Help with a regular expression for 0,1 or 2 decimal places « PHP « IT news, forums, messages
Re: Help with a regular expression for 0,1 or 2 decimal places

Posted by Al on 10/25/05 03:24

Shaun wrote:
> Hi,
>
> I am trying to create a regular expression for a width of a room, the value
> can be a whole integer (up to 999) with up to 2 decimal places -when it is
> stored in the database mysql will pad the value accordingly.
>
> /^[0-9]{1,3}.?[0-9]{0,2}?$/
>
> The only problem I have found with above is that I can enter 1.
>
> Is it possible to modify it so that I can only enter the decimal point if I
> enter at least digit after it?
>
> Also is there any difference between [0-9] and \d
>
> Thanks for your help

Try this..

^\d{1,3}($|\.\d{1,2}$)

1,2 or 3 digits followed by end OR decimal point and 1 or 2 digits and end of line.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация