Super2 Posted November 3, 2006 Share Posted November 3, 2006 in some of the form`s fields entries are numbers and if they are not - returns alert mesage or some message??Does someone have any idea?Sry about the English :) (if there are any mistakes ) Link to comment https://forums.phpfreaks.com/topic/26101-php-script-that-checks-if/ Share on other sites More sharing options...
HeyRay2 Posted November 3, 2006 Share Posted November 3, 2006 You can check if a variable contains only numbers in several ways:[b]is_numeric()[/b] method[code]<?php$foo = 20 // <== your variableif( is_numeric($foo) ){ echo 'Variable is a number.';} else { echo 'Variable is NOT a number';}?>[/code][b]Regular Expression[/b][code]<?php$foo = 20;if( preg_match('/^[0-9]$/', $foo)){ echo 'Variable is a number.';} else { echo 'Variable is NOT a number';}?>[/code]I'm assuming that you'll eventually want to check other fields that may not be numbers, so I would recommend creating an validation / error handling class like the one mentioned at the link below:http://www.phpfreaks.com/tutorials/117/0.php Link to comment https://forums.phpfreaks.com/topic/26101-php-script-that-checks-if/#findComment-119350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.