PHP Validating Numbers With Regular Expressions – String Function

<?phpif (! preg_match('/^-?\d+$/'$_POST['rating'])) {
    print 'Your rating must be an integer.';
}if (! preg_match('/^-?\d*\.?\d+$/',$_POST['temperature'])) {
   print 'Your temperature must be a number.';
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.