8, 10, 12, 981 (few area codes in Sweden). Total phone number can be 10 or 11 (digits only) If 8 + 9 or 10 digits if 981 + 7 or 8 digits Can this be done in regex?
something like that ..hm (8|10|12)\d{n} => Total Length 10 or 11
8, 10, 12, 981 (few area codes in Sweden). Total phone number can be 10 or 11 (digits only) If 8 + 9 or 10 digits if 981 + 7 or 8 digits Can this be done in regex?
something like that ..hm (8|10|12)\d{n} => Total Length 10 or 11
What about ^(?:8\d{9,10}|(?:10|12)\d{8,9}$
?
Edit: Then don't do it in regex. Pseudocode:
function check(number):
array areaCodes = array(8, 10, 12, 981)
if !number ~= '^\d{10,11}$':
return false
foreach in areaCodes as code:
if (substring(number, 0, length(code) - 1) == code) return true
return false
You will probably need to treat the different cases (i.e. area code length) separately, like:
^(8\d{9,10}|(10|12)\d{8,9}|981\d{7,8})$
Or you use a look-ahead or look-behind assertions:
^(?=\d{10,11})…$