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

Posted by "Richard Lynch" on 10/25/05 05:08

On Mon, October 24, 2005 3:59 pm, Shaun wrote:
> 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}?$/

Because '.' is special to preg, this expression ALSO matches:
12a25
5z43
7a

[aside]
Engineer: 7A, please.
Davey: What number, please?
Band: 7A!
Davey: All right, okay, just cuz I'm short
[/aside]

This might (or might not) do it:

/^[0-9]{1,3}(\\.[0-9]{1,2})?$/

The \\ is there so that PHP will turn it into \, and then you have \.
in the regular expression which the PRCE will interpret as "the
literal character known as 'dot'" instead of "any old character at
all"

> Also is there any difference between [0-9] and \d

Try it and see.

--
Like Music?
http://l-i-e.com/artists.htm

 

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

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