Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 4, 2019 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/175f13e1f88df9989cfdb983a578e870 to your computer and use it in GitHub Desktop.
Save parzibyte/175f13e1f88df9989cfdb983a578e870 to your computer and use it in GitHub Desktop.
import re
"""
Usar expresiones regulares para ver si es un correo electrónico válido en Python
Recuerda importar el módulo re
Por cierto, está probado con Python 3, si usas la versión 2 y no funciona, no trates
de adaptarlo, mejor actualiza tu versión
@author parzibyte
"""
def es_correo_valido(correo):
expresion_regular = r"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"
return re.match(expresion_regular, correo) is not None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment