Created
October 25, 2013 14:12
-
-
Save eduardonunesp/7155282 to your computer and use it in GitHub Desktop.
Validate UUID with Cerberus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from cerberus import Validator | |
class Validator(Validator): | |
def _validate_is_uuid(self, is_uuid, field, value): | |
re_uuid = re.compile(r'[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}', re.I) | |
if is_uuid and not re_uuid.match(value): | |
self._error("Value for field '%s' must be valid UUID" % field) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment