Solved Check if a string is not a UUID

Discussion in 'Plugin Development' started by mazentheamazin, Apr 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    mazentheamazin

    I was currently making a migration option for a plugin, and I was wondering if its possible to check if a string is not a UUID. Would I use some of the characteristics of a UUID to do this? Or is their a method available that I could use?
     
  2. Offline

    SnipsRevival

    I dont know if there is a better way, but you could try UUID.fromString(yourString) and catch the exception it throws if a UUID cannot be made from yourString.
     
    mazentheamazin likes this.
  3. Offline

    amhokies

    mazentheamazin
    The method above is definitely a good way to do it, but if you don't want to go the whole try/catch route, you can use regular expressions to test a string for the format of a UUID.

    regex: [a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}
     
    mazentheamazin likes this.
  4. Offline

    mazentheamazin

Thread Status:
Not open for further replies.

Share This Page