Created
August 4, 2012 06:27
-
-
Save JonCooperWorks/3255093 to your computer and use it in GitHub Desktop.
Custom WTForms Validators written in python
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 is_phone_number(form, field): | |
digits = filter(lambda x: x.isdigit(),field.data) | |
if len(digits) != 10 and len(digits) != 7: | |
raise validators.ValidationError(u'Invalid phone number') | |
def is_valid_header(form, field): | |
if '\n' in field.data or '\r' in field.data: | |
raise validators.ValidationError(u'Email headers cannot contain newlines') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment