#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Posts
    2
    Rep Power
    0

    UK Telephone Validation


    First post on here guys so please go easy on me .

    I am working on a contact form and require a regular expression which only allows for UK telephone numbers.

    I am currently using:

    Code:
    /^(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?$/
    This works well but I want to have the regex check that a valid telephone number is actually being entered and not just 00000000000. Does anyone know of a regex which can be used to do this?

    Thanks in advance!
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    What you're asking for is a way to tell if a phone number is usable, right? That it actually belongs to someone? You'll need a phone number database for that, which you'll have to use in conjunction with their real name and potentially address to be really sure.

    It's not worth the effort. If they want to be contacted via phone then they will enter their correct phone number, and if they do not then they will not.

    And speaking of being worth the effort, that regex is ridiculous. Why be so strict about it? Like, what if I type a space after "ext"? Or what if my extension is only two digits? What if I like typing phone numbers with periods as separators?
    Last edited by requinix; September 8th, 2016 at 04:15 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Posts
    2
    Rep Power
    0
    Yes, we are ultimately trying to check if the phone number is real. It is a request from the client that we have the system check the format of the number. The requirements for the input are for it to be quite strict. The idea you mention about the database is the ultimate way of checking but it is not really practical as you have kind of hinted at.

    In the UK we do not tend to enter periods or hyphens. We usually just write the number with just numbers i.e. 01278 123456 would be how we always write a telephone number.
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    "Client"? Remember that, besides doing the work they request, you also have an obligation to tell them when they're asking for something stupid. (Politely.) Because sometimes they just don't know. And validating the actual ownership of a phone number is stupid.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Posts
    1
    Rep Power
    0
    Originally Posted by davidlee
    Yes, we are ultimately trying to check if the phone number is real. It is a request from the client that we have the system check the format of the number. The requirements for the input are for it to be quite strict. The idea you mention about the database is the ultimate way of checking but it is not really practical as you have kind of hinted at.

    In the UK we do not tend to enter periods or hyphens. We usually just write the number with just numbers i.e. 01278 123456 would be how we always write a telephone number.
    If it absolutely has to be a real number just tie it into their phone system to ring them and ask for a code. But I doubt it is that important.

IMN logo majestic logo threadwatch logo seochat tools logo