mercredi 19 avril 2017

PHP: how to check if string is not numeric, but can contain spaces?

The goal is to validate a phone number that is numeric and may or may not contain spaces.

Eg, both '1800 123 456' and '1800123456' are acceptable.

Checking to see if it is not numeric is easy:

if(!is_numeric($phone_number)) {
  //display error message
}

But I am stuck as to how to pass it with spaces.

Would anyone be able to point me in the right direction with this?

Aucun commentaire:

Enregistrer un commentaire