Ticket #737: validators.py.diff

File validators.py.diff, 1.2 KB (added by mattimustang@…, 19 years ago)

isValidIPAddress4 enhancement

  • validators.py

     
    1919ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
    2020email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
    2121integer_re = re.compile(r'^-?\d+$')
    22 ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
     22ip4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$')
    2323phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
    2424slug_re = re.compile(r'^[-\w]+$')
    2525url_re = re.compile(r'^http://\S+$')
     
    9393            raise ValidationError, _("Enter valid e-mail addresses separated by commas.")
    9494
    9595def isValidIPAddress4(field_data, all_data):
    96     if ip4_re.search(field_data):
    97         valid_parts = [el for el in field_data.split('.') if 0 <= int(el) <= 255]
    98         if len(valid_parts) == 4:
    99             return
    100     raise ValidationError, _("Please enter a valid IP address.")
     96    if not ip4_re.search(field_data):
     97        raise ValidationError, _("Please enter a valid IP address.")
    10198
    10299def isNotEmpty(field_data, all_data):
    103100    if field_data.strip() == '':
Back to Top