If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

IN your models include

class IS_EMAIL_LIST(object):
    def __init__(self, error_message="Email %s is invalid", sep=","):
        self.error_message = error_message
        self.sep = sep

    def __call__(self, value):
            emails = value.strip().replace('\n','').replace('\t','').split(self.sep)
            for email in emails:
                email = email.strip()
                if IS_EMAIL()(email)[1] != None:
                    return (email, self.error_message % email)
            return (emails, None)

Now you can use it on tables you define:

db.define_table('invitation',
                Field('list','text', requires=IS_EMAIL_LIST())
                )

Users can pass in a text box:

"email1@gmail.com, email2@gmail.com, email3@g"

in the above case, last email adress will fire the validator to return an error message.

You can change the separator by defining the sep argument.

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere