Validation::decimal PHP Method

decimal() public static method

public static decimal ( $value, $places = null )
    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);
    }

Usage Example

コード例 #1
0
ファイル: ValidationTest.php プロジェクト: aichelman/StudyUp
 /**
  * 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'));
 }
All Usage Examples Of Validation::decimal