Hi, I tried the following two functions to check if a variable is numeric or not. The first function gave me a negative result. <?php $myvar = 123; if(!ereg("^[\d]*\.?\d*$",$myvar)) echo "Amount Should be Numeric."; else echo "Amount is numeric"; ?> PHP: But the second function worked. <?php $myvar = 123; if(!preg_match("/^[\d]*\.?\d*$/",$myvar)) echo "Amount Should be Numeric."; else echo "Amount is numeric"; ?> PHP: I could not understand the mystery behind it. Can you explain plz? Thanx
ereg uses POSIX.2 regular expressions syntax, so there is no "\d" there. Use "[[:digit:]]" insted of "\d" So, this is correct code: if(!ereg("^[[:digit:]]*\.?[[:digit:]]*$",$myvar)) PHP: