'amazon redshift regex pattern match digits other than 0 & 9 like 1111111111

I am trying to validate a field where values with repeating digits are not allowed. Like field should not have all these below cases

{'1111111111','2222222222','3333333333','4444444444','5555555555',
'6666666666','7777777777','8888888888'}

but 0000000000 and 9999999999 are ok.

I tried all the below patterns but I'm missing something small which I couldn't get through.

TRIM(field_nm) ~ '^\\d{10}$' AND TRIM(field_nm) !~ '^(0|9){10}$'
TRIM(field_nm) ~ '^\b\d{10}\b$'
TRIM(field_nm) ~ '^[1-8]{10}$'
TRIM(field_nm) ~ '^(?!0|9)(\1){10}'

But few are throwing error and few are matching when there is a digit repeating only twice or thrice like 9811115890.

Thanks in advance...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source