Re: Re: Help with a regular expression for 0,1 or 2 decimal places

From: Date: Tue, 25 Oct 2005 19:24:24 +0000
Subject: Re: Re: Help with a regular expression for 0,1 or 2 decimal places
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-224654@lists.php.net to get a copy of this message
Phillip Oertel wrote:
hi, i'm not a regex guru myself, but the following regex should work - tabke a look at my regex test setup ... <?php $test = array(
    "1",
    "1.",
    "1.2",
    "1.23",
    "1.234",
    "1234",
    "1234.",
    "1234.5",
    "1234.56",
    "1234.567"
); // if there's a dot, we want at least one number after it. $regex = '/^\d+(.\d{1,2})?$/';
Escape the decimal point. $regex = '/^\d+(\.\d{1,2})?$/'; -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.com

« previous php.general (#224654) next »