Skip to content

Commit

Permalink
default regex validators
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Nov 11, 2017
1 parent a6c8e5b commit 8eca728
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pydal/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shutil
import sys
import types
import re
from collections import OrderedDict
from ._compat import (
PY2, StringIO, BytesIO, pjoin, exists, hashlib_md5, basestring, iteritems,
Expand Down Expand Up @@ -41,6 +42,17 @@
'blob': 2**31}


DEFAULT_REGEX = {
'id': '[1-9]\d*',
'decimal': '\d{1,10}\.\d{2}',
'integer': '[+-]?\d*',
'float': '[+-]?\d*(\.\d*)?',
'double': '[+-]?\d*(\.\d*)?',
'date': '\d{4}\-\d{2}\-\d{2}',
'time': '\d{2}\:\d{2}(\:\d{2}(\.\d*)?)?',
'datetime':'\d{4}\-\d{2}\-\d{2} \d{2}\:\d{2}(\:\d{2}(\.\d*)?)?',
}

class Row(BasicStorage):

"""
Expand Down Expand Up @@ -1612,7 +1624,8 @@ def __init__(self, fieldname, type='string', length=None, default=DEFAULT,
self.ondelete = ondelete.upper() # this is for reference fields only
self.notnull = notnull
self.unique = unique
self.regex = regex
# split to deal with decimal(,)
self.regex = regex or DEFAULT_REGEX.get(self.type.split('(')[0])
self.options = options
self.uploadfield = uploadfield
self.uploadfolder = uploadfolder
Expand Down

0 comments on commit 8eca728

Please sign in to comment.