fork download
  1. <?php
  2. $inputArr = array(
  3. "0",
  4. "0.1",
  5. " 0.1 ",
  6. "0,00002",
  7. "123.456",
  8. "12345678",
  9. "12345678.9999",
  10. "123456789",
  11. "123456789.0001"
  12. );
  13.  
  14. $pattern = "~^\s*\d{1,8}(?:\.\d{1,4})?\s*$~";
  15. forEach($inputArr as $input) {
  16. $match = ($input > 0) && preg_match($pattern, $input);
  17. echo("Input: '" . $input . "' -> " . ($match ? "TRUE" : "FALSE") . "\n");
  18. }
  19. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Input: '0'  ->  FALSE
Input: '0.1'  ->  TRUE
Input: ' 0.1 '  ->  TRUE
Input: '0,00002'  ->  FALSE
Input: '123.456'  ->  TRUE
Input: '12345678'  ->  TRUE
Input: '12345678.9999'  ->  TRUE
Input: '123456789'  ->  FALSE
Input: '123456789.0001'  ->  FALSE