regex - PostgreSQL check constraint not working -
I am trying to bring down barriers to postgresql which checks columns WOD for patterns. If the pattern does not match, then the error should be thrown.
Contract wicking check (wcode :: text ~ '[\ w] {4,4} - [\ w] {2,2} - [\ w] {1,1} :: text); Geniun input string is "AA14-AM-1" which actually works but the problem is that if I use "AA14-AM-14" or "AA-14-AM - 1444 ", then it does not do this through an error I want to restrict the input to use this (" AA-14-AM-1 ") pattern.
You have an "unlimited" regex (not sure that this is the right technical term). Which basically means that the pattern has come anywhere inside the input string. To match the input string with the exact pattern, you need "anchored" regex: contract wcoding check (wcode :: text ~ '^ [ \ W] {4,4} - [\ w] {2,2} - [\ w] {1,1} $ '); The "anchor" pattern on the start and end of the ^ and $ which indicates the result that the input string should match the pattern Absolutely (do not allow pattern as a sub-string of a long input value).
Comments
Post a Comment