That syntax is invalid, so it can never work. At minimum you'd need to quote the pattern values in the LIKE
expressions. They must also have wildcards so they aren't anchored; at the moment, your expression tries to say "value must be a single character that is a letter, and a single character that is a number". Which is impossible. Additionally, you can't use character classes ([...])
in LIKE
.
What you want is to use a pair of simple regular expressions instead. This:
CHECK (thevalue ~ '[[:alpha:]]' AND thevalue ~ '\d')`
would do.
You can play some simple games with the expression to force this into a single regular expression, but I don't think there's much point, it'll just be harder to read and uglier.
All that said, I'm worried that you might be attempting to validate password strength. If you are doing that then this is absolutely the wrong way to go about it. Do not use a CHECK
constraint - you won't be able to introduce stronger requirements later until all existing rows pass the constraint. Do the check as input validation in your application instead, and use proper password strength checking tools - which already exist - instead of rolling your own.