Why do you care where users care to break up the groups of digits or what characters they use to do so? Around here (Sweden), it's common to see one person write a given phone number as 046 123 456 789
and someone else write it 046 123 45 67 89
, but both are dialed identically and are equally valid. (As, for that matter, would be 04 61 2345 6 78 9
- not a format I've ever seen used, but it still dials identically.)
Just strip out non-numeric characters (other than a leading +
, since that's meaningful), check that it's a reasonable number of digits, store that, and render it into your preferred format when displaying the number. Or keep the format as entered by the user, although then you need to take the normal precautions to prevent SQL injection, CSS, XSRF, etc. attacks.