Add basic/generic email validator logic
for use mostly in non-web scenarios, probably
This commit is contained in:
parent
a8db5db308
commit
684363bcde
2 changed files with 26 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -35,6 +35,7 @@ import humanize
|
|||
from rattail.time import timezone, make_utc
|
||||
from rattail.files import resource_path
|
||||
|
||||
import colander
|
||||
from pyramid.renderers import get_renderer
|
||||
from webhelpers2.html import HTML, tags
|
||||
|
||||
|
@ -175,3 +176,25 @@ def get_effective_theme(rattail_config, theme=None, session=None):
|
|||
raise ValueError("theme not available: {}".format(theme))
|
||||
|
||||
return theme
|
||||
|
||||
|
||||
def validate_email_address(address):
|
||||
"""
|
||||
Perform basic validation on the given email address. This leverages the
|
||||
``colander`` package for actual validation logic.
|
||||
"""
|
||||
node = colander.SchemaNode(typ=colander.String)
|
||||
validator = colander.Email()
|
||||
validator(node, address)
|
||||
return address
|
||||
|
||||
|
||||
def email_address_is_valid(address):
|
||||
"""
|
||||
Returns boolean indicating whether the address can validate.
|
||||
"""
|
||||
try:
|
||||
validate_email_address(address)
|
||||
except colander.Invalid:
|
||||
return False
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue