shakeit Posted January 29, 2008 Share Posted January 29, 2008 Hello everybody... You've helped me out a couple of times and I am still comming back :-) I need some help on a ereg issue, where I want to make a function where ONLY digits are possible when writing something in a field... i.e. only 0,1,2,3,4,5,6,7,8,9,10,..... However, I thought the function below did that, but only to a certain point... if I write only letters then I will get false, which is ok.. but if I write digits first and then letters, 55aabb, then I get true... Do you see my problem? I only want it to allow digits, nothing else: public function validatePhone($validate) { $goodChars = "^[0-9]"; if( ereg("$goodChars",$validate) ) { // if there are less than 8 digits, then its not correct. if( strlen($validate) < 8 ) { return false; } else { return true; } } else { return false; } } PS! I also have the same problem when I only want to allow letters in another function .. So please help me, AGAIN :-) Thanx in advance Link to comment https://forums.phpfreaks.com/topic/88411-solved-ereg-help/ Share on other sites More sharing options...
effigy Posted January 29, 2008 Share Posted January 29, 2008 The expression ^[0-9] must match at least one digit at the beginning of the string to be valid. To extend this to the entire string use ^[0-9]+$. Moreover, see ctype_digit. Link to comment https://forums.phpfreaks.com/topic/88411-solved-ereg-help/#findComment-452491 Share on other sites More sharing options...
shakeit Posted January 30, 2008 Author Share Posted January 30, 2008 Thanx a lot :-) Ut worked ... Link to comment https://forums.phpfreaks.com/topic/88411-solved-ereg-help/#findComment-453241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.