Created
May 16, 2013 18:33
-
-
Save fmariluis/5593958 to your computer and use it in GitHub Desktop.
Some custom validators for Argentina. Useful for Django
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
def phone_validator(value): | |
""" | |
Valida un teléfono de Argentina con código de área | |
10 dígitos, sin 0 al comienzo ni caracteres como - o () | |
""" | |
pattern = '^[0]|\D' | |
if len(value) != 10: | |
raise ValidationError("Verifique la cantidad de dígitos. Deben ser 10 sin el \ | |
15 e incluyendo el código de área") | |
if search(pattern, value): | |
raise ValidationError( | |
"No agregue un 0 al comienzo y sólo utilice números por favor.") | |
def dni_validator(value): | |
""" | |
Valida un DNI de Argentina | |
Hasta 8 dígitos, sin caracteres extraños | |
""" | |
pattern = '^[0]|\D' | |
if len(value) > 8: | |
raise ValidationError( | |
"Verifique la cantidad de dígitos. Deben 8 como máximo.") | |
if search(pattern, value): | |
raise ValidationError( | |
"Sólo utilice números por favor.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment