I need to write a constraint in db2 where the username has to start with @ followed by alphanumeric pattern, can have maximum length of 31 and can only contain lowercase alphabets, numbers and _ (underscore) symbol. I did this:
ALTER TABLE KUNDENKONTAKTDATEN ADD CONSTRAINT
TwitterID_CHECK CHECK ( trim(length(TWITTER_ID)) <= 31 AND TWITTER_ID like '@%')
My problem is for the part only containing lowercase alphabets, numbers and _ .
This is my homework question and the tips were to use functions like Trim, Translate, Length and Substr but I am allowed to use other functions. Internet told me use fn:matches function but I am not sure how it works.
Can anybody please help me solve this with or without using fn:matches?
Thank you in advance
Edit: Not actually a duplicate to this but similar method can be applied to check if it contains illegal value. This question is not only about finding if a column consists special characters. Parts of my question that are unique are: length, starting with, not finding if it has special character but allowing only one special character (_) as a value and therefore not a duplicate.