Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

reg ex help

Options
  • 31-08-2007 8:43am
    #1
    Registered Users 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