Is it possible to check with regex:
You can use
^(?:[78]\d{10}|1\d{9}|0\d{6}(?:[87]\d|\d1)\d{9})$
See the regex demo
Details
^
- start of string(?:[78]\d{10}|1\d{9}|0\d{6}(?:[87]\d|\d1)\d{9})
- one of the three alternatives:
[78]\d{10}
- 7
or 8
and then 10 digits (11 all in all)|
- or1\d{9}
- 1
and then 9 digits (10 all in all)|
- or0\d{6}(?:[87]\d|\d1)\d{9}
- 0
, then 6 digits, then the 8th digit equal to 8
or 7
and any one digit, or any one digit and the 9th digit equal to 1
, and then 9 more digits (=18 digits)$
- end of string.Here's the regex: /^[78]\d{10}$/
"^" indicates the start of the line "$" indicates the end of the line \d means digits {10}means exactly 10 [] is a group of valid values
The second question is dependant on wether your Engine supports Lookahead and Lookbehind https://www.regular-expressions.info/conditional.html