cgm225 Posted May 25, 2008 Share Posted May 25, 2008 What is the regular expression for just numbers? I have this for numbers and letters: $regex = '/[^-_A-z0-9]++/'; Link to comment https://forums.phpfreaks.com/topic/107181-what-is-the-regular-expression-for-just-numbers/ Share on other sites More sharing options...
BlueSkyIS Posted May 25, 2008 Share Posted May 25, 2008 remove the letters? $regex = '/[^0-9]++/'; Link to comment https://forums.phpfreaks.com/topic/107181-what-is-the-regular-expression-for-just-numbers/#findComment-549527 Share on other sites More sharing options...
Orio Posted May 26, 2008 Share Posted May 26, 2008 That will match "everything BUT numbers". Also you need only one "+" (or "*", depends on what you're looking for). Anyway, it should look like this: <?php if(preg_match("/^[0-9]+$/", $num_input)) echo "Valid input"; ?> Orio. Link to comment https://forums.phpfreaks.com/topic/107181-what-is-the-regular-expression-for-just-numbers/#findComment-550350 Share on other sites More sharing options...
teng84 Posted May 27, 2008 Share Posted May 27, 2008 you you only need to validate numbers simply use ctype_digit or is_numeric Link to comment https://forums.phpfreaks.com/topic/107181-what-is-the-regular-expression-for-just-numbers/#findComment-550588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.