Page 1 of 1

ctype_digit but allow spaces

Posted: Mon Apr 10, 2006 1:09 pm
by ed209
I want to validate some data - it has to be a phone number so only numbers, but I'd also like to allow spaces. can I use ctype_digit in combination with something?

Posted: Mon Apr 10, 2006 1:13 pm
by feyd
Only if you remove the spaces could you use ctype_digit(). Best use a regular expression I think.

Posted: Mon Apr 10, 2006 1:24 pm
by ed209
good point, why didn't I think of that :roll: . a simple

Code: Select all

$number = str_replace(" ", "", $tel);

//then 

ctype_digit($number):
did the trick. I've yet to learn regex