regex for phone number
Posted: Mon Jul 09, 2012 3:14 am
Rules:
1. must start with number
2. sum of numeric must be between 7-12 inclusive
3. other valid non-numeric characters include space (" ") and hyphens ("-")
4. no more than one consecutive valid non-numeric characters allowed ("1 2-3" is allowed, "1-2" is allowed, but "1--2" is not, "1- 2" is also not allowed)
right now my regex is this:
\\d([- ]?\\d[- ]?){6,11}
but it passed the test 123--4567. What's wrong? thanks
1. must start with number
2. sum of numeric must be between 7-12 inclusive
3. other valid non-numeric characters include space (" ") and hyphens ("-")
4. no more than one consecutive valid non-numeric characters allowed ("1 2-3" is allowed, "1-2" is allowed, but "1--2" is not, "1- 2" is also not allowed)
right now my regex is this:
\\d([- ]?\\d[- ]?){6,11}
but it passed the test 123--4567. What's wrong? thanks