Hi,

I think these validators would be a nice addition to the great set of
validators we already have. They can be useful for fields for names
and phone numbers.


class IS_LETTERS(Validator):
    """
    Checks if field's value consists of all letters

    example::

        INPUT(_type='text', _name='name', requires=IS_LETTERS())

        >>> IS_LETTERS()("A")
        ('A', None)
        >>> IS_LETTERS()("")
        ('', None)
        >>> IS_LETTERS()("A_")
        ('A_', 'enter only letters')
        >>> IS_LETTERS()("!")
        ('!', 'enter only letters')
    """

    def __init__(self, error_message='enter only letters'):
        IS_MATCH.__init__(self, '^[A-Za-z]*$', error_message)

class IS_DIGITS(Validator):
    """
    Checks if field's value consists of all numeric digits

    example::

        INPUT(_type='text', _name='name', requires=IS_DIGITS())

        >>> IS_NUMBERS()("1")
        ('1', None)
        >>> IS_NUMBERS()("")
        ('', None)
        >>> IS_NUMBERS()("A")
        ('A', 'enter only numbers')
        >>> IS_NUMBERS()("!")
        ('!', 'enter only numbers')
    """

    def __init__(self, error_message='enter only digits'):
        IS_MATCH.__init__(self, '^[0-9]*$', error_message)


Regards,
Saurabh Sawant

Reply via email to