From PHP sanitize filters list there is one option to sanitize integers:
FILTER_SANITIZE_NUMBER_INT - Remove all characters except digits, plus and minus sign.
If we use:
filter_var($var2San, FILTER_SANITIZE_NUMBER_INT);
This will clean dots .
and commas ,
but the +
and -
signs remain. E.g.: ++++ --- 1.110,4 <b>m<sup>2</sup></b>
is sanitized to ++++---111042
. Ideally the filter_var
would return false
when the number was 0, i.e. the number would have to be a natural number, more specifically, a positive integer.
Therefore a FILTER_SANITIZE_NUMBER_NATURAL
would be handy... Is there a workaround for this or do I need a RegExp?