I need a REGEX with following specifications:
- Allowed chars:
(blank space),
(
,)
,+
,–
, 0-9 (
can be first char after trim like(+61) 312 405 678
or+61 312 405 678
- Length: min 8 characters max 16 – show error in case of boundary conditions.
I need a REGEX with following specifications:
(blank space), (
, )
, +
, –
, 0-9(
can be first char after trim like (+61) 312 405 678
or +61 312 405 678
I would rather stick with standards and won't reinvent the wheel. You can use a special library for handling phone numbers called libphonenumber
Not a duplicate, but this may give some answers. My approach would be to strip out the characters that aren't digits (aside from +) and then process the regex based on that. Should be a lot easier to deal with.
You could also try http://regexlib.com.
According to your specifications, this regex would work:
[-+\d() ]{8,16}
This will also match (--++--)
, so you may want to change/clarify your specs.
Also, regex do not "show error", the only thing they do is match or not.