Created
August 28, 2009 11:33
-
-
Save gabrielfalcao/176915 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Copyright (C) <2009> Gabriel Falcão <[email protected]> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
import re | |
import formencode | |
from formencode import validators | |
class UsernameValidator(formencode.FancyValidator): | |
def _to_python(self, value, state): | |
if not re.match(r"^[a-zA-Z][\w._-]+$", value): | |
raise formencode.Invalid( | |
'Invalid username, it must start with a letter, and' | |
'contain only alpha-numeric, dot, underscore or dash', | |
value, state) | |
return value | |
class Registration(formencode.Schema): | |
name = validators.String(not_empty=True) | |
email = validators.Email(not_empty=True) | |
username = UsernameValidator(not_empty=True) | |
password = validators.String(not_empty=True) | |
password_confirm = validators.String() | |
chained_validators = [validators.FieldsMatch( | |
'password', 'password_confirm')] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment