I am trying to validate a String in Java to see if it matches the randomUUID format using the following regex
^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$
Now this works fine and picks up invalid strings and so on – however, if I pass a null String to the regex, it returns true, so when I perform validation on the Pattern annotation, no constraint violations are reported. Is this expected behaviour, since the String is null it is not performing any validation?
As a way around this, on the getter method that I have annotated with the Pattern annotation, I have used this
return id != null ? id : "null"
This works, however it seems a bit... hacky to me :)