grantf Posted March 30, 2008 Share Posted March 30, 2008 Hi, i am trying to validate a field so that it contains only numbers and spaces.. this is what i have. It is denying me spaces... if(ereg('[\' " ! @ # $ % ^ : ; < > & * , . ? ( ) _ ~ ` + - = a-zA-Z]', $field)) does anyone know why it is doing this? Thanks. Link to comment https://forums.phpfreaks.com/topic/98716-ereg-search-pattern/ Share on other sites More sharing options...
effigy Posted March 31, 2008 Share Posted March 31, 2008 if (preg_match('/\A[\d ]+\z/', '', $string)) Link to comment https://forums.phpfreaks.com/topic/98716-ereg-search-pattern/#findComment-505675 Share on other sites More sharing options...
grantf Posted April 2, 2008 Author Share Posted April 2, 2008 thanks for the reply however that does not stop other characters from being allowed. essentially only numbers and spaces are to be validated, everything else denied. thanks.. Link to comment https://forums.phpfreaks.com/topic/98716-ereg-search-pattern/#findComment-507029 Share on other sites More sharing options...
grantf Posted April 2, 2008 Author Share Posted April 2, 2008 Hi all, i now have the solution.. if(preg_match('/^[0-9 ]+$/D', $s)) ok... or if(!preg_match('/[^0-9 ]/', $s)) ok... Cheers. Link to comment https://forums.phpfreaks.com/topic/98716-ereg-search-pattern/#findComment-507039 Share on other sites More sharing options...
effigy Posted April 2, 2008 Share Posted April 2, 2008 My mistake. The extra quotes in the middle should not be there: if (preg_match('/\A[\d ]+\z/', $string)) Link to comment https://forums.phpfreaks.com/topic/98716-ereg-search-pattern/#findComment-507469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.