<?php
$testValues = [
'positives' => ['121', '231.45', '77,65', '9.456,77', '4,255.66'], // should pass
'negatives' => ['-121', '-231.45', '-77,65', '-9.456,77', '-4,255.66'], // should pass
'gibberish' => ['231.45a', '7a7,65', 'a9.456,77', '4,255.66a', 'aaaaaa'], // should fail
];
function customIsNumeric(string $value): bool
{
return is_numeric(str_replace(['.', ','], '', $value));
}
foreach ($testValues as $category => $values) {
var_dump($category);
foreach ($values as $value) {
var_dump(customIsNumeric($value));
}
}
preferences:
25.4 ms | 406 KiB | 5 Q