Skip to content

Instantly share code, notes, and snippets.

@rxdazn
Created September 6, 2013 02:16
Show Gist options
  • Save rxdazn/6458754 to your computer and use it in GitHub Desktop.
Save rxdazn/6458754 to your computer and use it in GitHub Desktop.
def length(min=-1, max=-1):
message = 'Must be between %d and %d characters long.' % (min, max)
def _length(form, field):
l = field.data and len(field.data) or 0
if l < min or max != -1 and l > max:
raise ValidationError(message)
return _length
class MyForm(Form):
name = TextField('Name', [Required(), length(max=50)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment