PHP Regular Expressions

I am trying to figure out how to validate a phone number using ereg().

I basically want it to check whether the entered string is made up of only numbers. Main concern is how do I remove spaces if the user has entered any and how not to make that not upset it if they didn;t enter any numbers?

I would recommend against ereg(). It’s deprecated and even removed in PHP6.

Preg is the more up-to-date and advanced library.

What I’m wondering is if you really need regex here at all. If all you want to do is remove spaces, you could use:

$TelephoneNumber = '01234 567890';
$TelephoneNumber = str_replace(' ', '', $TelephoneNumber);

ok, Thanks, I’ll go and have a look at Preg