How to judge a string is UUID type? [duplicate]
Handle the exception and do something in that case. For example :
try{
UUID uuid = UUID.fromString(someUUID);
//do something
} catch (IllegalArgumentException exception){
//handle the case where string is not valid UUID
}
You should use regex to verify it e.g.:
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
test it with e.g.g 01234567-9ABC-DEF0-1234-56789ABCDEF0
or with brackets
^\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}?$