简体   繁体   English

如何使用groovy脚本在Jmeter中验证有效的GUID?

[英]How to validate a valid GUID in Jmeter using groovy script?

This is the valid GUID 04a8b9f1-4a92-f21c-94f9-1544fa539f44 and i want to validate it. 这是有效的GUID 04a8b9f1-4a92-f21c-94f9-1544fa539f44,我想对其进行验证。 Thanks. 谢谢。

You can validate by calling UUID.fromString method 您可以通过调用UUID.fromString方法进行验证

UUID uuid = UUID.fromString(someUUID);

If UUID is invalid it will throw an exception 如果UUID无效,它将引发异常

Creates a UUID from the string standard representation as described in the toString() method. 如toString()方法中所述,根据字符串标准表示创建UUID。

I have solved the above issue. 我已经解决了上述问题。

String valid = "04a8b9f1-4a92-f21c-94f9-1544fa539f44";
        if (valid .matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"))
        {
            return true;
        }
        else
        {
            return false;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM