i am writing a php app that asks people for their phone number in lebanon. I don’t want to be very strict in the entry format so i’m running into some trouble validating.
A lebanese phone number looks like that.
961 3 123456
961: the country code. i want it to be valid with or without it.
3: the area code. here’s where it is tricky. the possible area codes are 03, 70 and 71. when the country code is present, 03 drops the 0 and becomes 3 while 70 and 71 are as is with or without country code.
123456: the phone number, always 6 digits.
here are the formats i’m trying to validate:
961 3 123456
961 70 123456
961 71 123456
03 123456
70 123456
71 123456
the spaces are here just for the sake of clarity, i am validating after stripping all spaces and non alphanumeric characters.
that’s it, would be great if someone can help.
thanks
I’m sure there’s a slicker way to do it, but
seems to work, assuming I understand the requirements.