function isValidEmail($email)
{
if(version_compare(PHP_VERSION, '5.2.0', '>=')
return filter_var($email, FILTER_VALIDATE_EMAIL);
else
return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email);
}
Here it is a function for checking if a field value represent a number. Floating point and negative numbers are also considered.
CREATE FUNCTION IsNumeric (sIn varchar(1024)) RETURNS tinyint
RETURN sIn REGEXP '^(-|\\+){0,1}([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$';
Via:
Stack Overflow.
If you use is_numeric function, you could note that 45,362.00 or 45.362,00 are not numbers for this function (only one dot is permitted).
So here it is a function (taken from this comment) that uses regular expression to extend is_numeric functionality:
function my_is_numeric($value) {
$american = preg_match ("/^(-){0,1}([0-9]+)(,[0-9][0-9][0-9])*([.][0-9]){0,1}([0-9]*)$/" ,$value) == 1;
$world = preg_match ("/^(-){0,1}([0-9]+)(.[0-9][0-9][0-9])*([,][0-9]){0,1}([0-9]*)$/" ,$value) == 1;
return ($american or $world);
}
$numbers = array("72", "15.3", "45,362.00", "45.362,00", "62.3692,00", "15:15:00", "15,3");
foreach($numbers as $val)
echo "$val is numeric? D: ".is_numeric($val)." M:".my_is_numeric($val)."
";
…and the result is:
72 is numeric? D: 1 M:1
15.3 is numeric? D: 1 M:1
45,362.00 is numeric? D: M:1
45.362,00 is numeric? D: M:1
62.3692,00 is numeric? D: M:
15:15:00 is numeric? D: M:
15,3 is numeric? D: M:1