java - Validate UUID without divider "-" -
i uuids in format "005056963ab75fd48bdc59c100314c40" , want validate them. tried code this:
public boolean isuuid(string uuid){ try { uuid.fromstring(uuid); } catch (exception e) { return false; } return true; }
but tell me "005056963ab75fd48bdc59c100314c40" not valid id. site http://guid.us/test/guid on other hand tells me , gives me uuid "-" added. there elegant way validate uuid in java or have manually add "-" right places?
try regex
uuid = uuid.replaceall("(.{8})(.{4})(.{4})(.{4})(.+)", "$1-$2-$3-$4-$5"); uuid.fromstring(uuid);
Comments
Post a Comment