Posted by Rik Wasmus on 10/18/07 11:44
On Thu, 18 Oct 2007 10:42:20 +0200, <davranfor@gmail.com> wrote:
> Same but numbers can't be lesser than the previous number, must be
> equal or greater, is this possible with regex??
>
> 0-45-90-120 -> Valid
> 0-45-45-90 -> Valid
> 0-90-45-120 -> Invalid
Maybe it's possible. I wouldn't do it with a regex anymore though.
function _my_validate($string){
$array =3D explode('-',$string);
if(!is_array($array)) return false;
$previous =3D 0;
foreach($array as $value){
if(
intval($value)!=3D $value
||
$value < $previous
||
$value > 999
) return false;
$previous =3D $value;
}
return true;
}
-- =
Rik Wasmus
[Back to original message]
|