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. Quote Link to comment Share on other sites More sharing options...
effigy Posted March 31, 2008 Share Posted March 31, 2008 if (preg_match('/\A[\d ]+\z/', '', $string)) Quote Link to comment 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.. Quote Link to comment 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. Quote Link to comment 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)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.