mysql - Php- Check string is either a decimal or fractions -
i have input box users can type in odds bet. can either in form of decimal -> 1 or 6.2 ect or fraction e.g 5/1 or 13/2 ect
what best way check these input?
i think regex best way this
if(preg_match("@^\d*\.?\d+(/\d*\.?\d+)?$@", $value)) { echo "$value valid"; }
this regex allow : .1 | 2.0/54 | 2.3 | .5/.8 | 8/7 | 85.98 | .....
if need ,
character (for language use it) "@^\d*[\.,]?\d+(/\d*[\.,]?\d+)?$@""
edit fixed "4/" case
Comments
Post a Comment