Skip to content

Instantly share code, notes, and snippets.

@goujonbe
Last active October 31, 2020 16:22
Show Gist options
  • Save goujonbe/be9dabaf46239028fa9bd5f47c1e445e to your computer and use it in GitHub Desktop.
Save goujonbe/be9dabaf46239028fa9bd5f47c1e445e to your computer and use it in GitHub Desktop.
class InvalidEmailAddressError(Exception):
pass
def validate_email_address(ctx, param, value):
regex = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$"
if not re.search(regex, value):
raise InvalidEmailAddressError(f"Invalid email address: {value}")
return value
@click.command()
@click.option("--email", callback=validate_email_address)
def main(email):
print(f"login: {email}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment