Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

reg ex help

  • 31-08-2007 08:43AM
    #1
    Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭


    hello

    I want to validate a phone number
    the logic is as follows

    0 or 1 '+'

    followed by at least 6 digits and as many spaces in between

    so I had this expression
    [+]?\\s]*[\\d{6,}$
    so [+]? = + once or not at all
    and [\s]*[\d]{1} (lets call this A)= zero or more whitespace charaters followed by a 1 digit
    [A]{6,0} = A to be true at least 6 times

    but yet the phone number
    77 77 comes back as true
    even though I'm looking for 6 digits

    any body any clue of where my logic is wrong?


Comments

  • Closed Accounts Posts: 8 sure22


    Once regex sees square brackets it tries to match one of the items in the brackets, I think this is where your problem lies. Try this instead
    [+]?\\s*\\d{6,}$


  • Closed Accounts Posts: 8 sure22


    Doh! with the round brackets

    [+]?(\\s*\\d\\s*){6}$


Advertisement