Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created October 25, 2013 14:12
Show Gist options
  • Save eduardonunesp/7155282 to your computer and use it in GitHub Desktop.
Save eduardonunesp/7155282 to your computer and use it in GitHub Desktop.
Validate UUID with Cerberus
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