I want to validate a phone number as follows - minimum 10 digits, allow spaces, allow hyphen, and allow round brackets.

I have the following so far but it doesn't seem to work:

(!preg_match('/\d\s-(){10,}+$/', $phone))

Anyone got any ideas what I'm doing wrong?

    Here's what your pattern currently says:

    1. Match one digit.

    2. Match one whitespace character.

    3. Match one hyphen.

    4. Match a left parenthesis.

    5. Match a right parenthesis that appears 10 or more times. Repeat that '10 or more times' for one or more times.

    In other words, a string would have to be like this:

    1 -())))))))))

    in order to match your pattern. Somehow I don't think that matches up with your description of what you're after.

    If you just want to allow any of those characters to appear 10 or more times, then move them all into a character class (e.g. with square brackets).

      Thanks so much. I changed it to:

      (!preg_match('/[\d\s-()]{10,}$/', $phone)

      and it seems to work how I want it to. 🙂

        So in other words, this:

        ))))))))))

        is a valid phone number? 😉

          mmm... i better work on it more 😛

            Write a Reply...