验证用户输入的UUID

时间:2019-04-28 01:57:31

标签: java uuid

我正在尝试验证用户的UUID输入。我在这里尝试过以前类似问题的建议...

private static final Pattern pattern = Pattern
.compile("(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-5][0-9a-f]{3}-?[089ab][0-9a-f]{3}-?[0-9a-f]{12}$");

private static final Pattern pattern = Pattern
.compile("/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i");

private static final boolean isValidUuid(final String uuid) {
        return ((uuid != null) && (uuid.trim().length() > 31)) ? pattern.matcher(uuid).matches() : false;
      }

public boolean isUUID(String s){
        return s.matches("/^[0-9a-f]{8}-?[0-9a-f]{4}-?[1-5][0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i");
    }

UUID id = UUID.toString(inputUUID) 
id.toString().equals(inputUuid)

这些方法均未成功验证用户输入的“ 00000000000000000000000000000001”

感谢任何建议!

0 个答案:

没有答案