public static function decimal($value, $places = null)
{
if (is_null($places)) {
$regex = '/^[+-]?[\\d]+\\.[\\d]+([eE][+-]?[\\d]+)?$/';
} else {
$regex = '/^[+-]?[\\d]+\\.[\\d]{' . $places . '}$/';
}
return (bool) preg_match($regex, $value);
}
/** * testDecimalCustomRegex method * * @return void */ public function testDecimalCustomRegex() { $this->assertTrue(Validation::decimal('1.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s')); $this->assertFalse(Validation::decimal('.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s')); }