如何测试有效的UUID / GUID? [英] How to test valid UUID/GUID?
问题描述
如何检查变量是否包含有效的UUID / GUID标识符?
How to check if variable contains valid UUID/GUID identifier ?
我目前只对验证类型1和4感兴趣,但它不是对你的答案的限制。
I'm currently interested only in validating types 1 and 4, but it's not limit for your answer.
推荐答案
目前,UUID是在RFC4122中指定的。
Currently, UUID's are as specified in RFC4122.
因此要验证UUID ......
Therefore to validate a UUID...
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
...确保您拥有版本1到5的规范格式化UUID,并且是适当的变体根据RFC4122。
...ensures you have a canonically formatted UUID that is Version 1 through 5 and is the appropriate Variant as per RFC4122.
注意:大括号 {
和}
不是规范的。它们是某些系统和用法的工件。
NOTE: Braces {
and }
are not canonical. They are an artifact of some systems and usages.
易于修改上述正则表达式以满足原始问题的要求。
Easy to modify the above regex to meet the requirements of the original question.
提示:正则表达式组/捕获
HINT: regex group/captures
这篇关于如何测试有效的UUID / GUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!