Question

In my program I am using a line as follows to generate a string UUID

final String value= UUID.randomUUID().toString();

suppose I get the given sting value as UUID string

581572cb-d8bb-49f9-a664-9d692a7c7a87

How can I make sure that the received string belongs to a correct UUID ?

I already visited,

java.util.UUID.fromString not checking length

to have the answer, but still not sure what to use what to do ?

Was it helpful?

Solution

Use regex: [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} to check a valid UUID.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top