Created
September 6, 2013 02:16
-
-
Save rxdazn/6458754 to your computer and use it in GitHub Desktop.
This file contains 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
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