Skip to content

Instantly share code, notes, and snippets.

@JonCooperWorks
Created August 4, 2012 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonCooperWorks/3255093 to your computer and use it in GitHub Desktop.
Save JonCooperWorks/3255093 to your computer and use it in GitHub Desktop.
Custom WTForms Validators written in python
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