Sachin Sachin - 4 months ago 9x
Java Question

RegEx to validate contact number

I want to validate contact number for swedish region,
I need regx which will fulfill following conditions :

  1. Apply a filter that only allows numbers (+46xxx, 0046xxx, 0xxx).

  2. No international numbers allowed (00[other than 46], +[other than 46])

  3. Also block premium numbers (09xxx, +469xxx, 00469xxx)

I tried to generate it but it couldn't satisfy the requirement



Replace [+46|0046|0] with (?:\+46|0046|0(?!0)) in your regex


Regex explanation here.

Regular expression visualization

Refer : What is the difference between square brackets and parentheses in a regex?