def clean(self, value): # strip spaces and dashes value = value.strip().replace(' ', '').replace('-', '') super(ZAIDField, self).clean(value) if value in EMPTY_VALUES: return '' match = re.match(id_re, value) if not match: raise ValidationError(self.error_messages['invalid']) g = match.groupdict() try: # The year 2000 is conveniently a leapyear. # This algorithm will break in xx00 years which aren't leap years # There is no way to guess the century of a ZA ID number d = date(int(g['yy']) + 2000, int(g['mm']), int(g['dd'])) except ValueError: raise ValidationError(self.error_messages['invalid']) if not luhn(value): raise ValidationError(self.error_messages['invalid']) return value
def clean(self, value): # strip spaces and dashes value = value.strip().replace(" ", "").replace("-", "") super(ZAIDField, self).clean(value) if value in EMPTY_VALUES: return u"" match = re.match(id_re, value) if not match: raise ValidationError(self.error_messages["invalid"]) g = match.groupdict() try: # The year 2000 is conveniently a leapyear. # This algorithm will break in xx00 years which aren't leap years # There is no way to guess the century of a ZA ID number d = date(int(g["yy"]) + 2000, int(g["mm"]), int(g["dd"])) except ValueError: raise ValidationError(self.error_messages["invalid"]) if not luhn(value): raise ValidationError(self.error_messages["invalid"]) return value
def clean(self, value): super(FRSIRENENumberMixin, self).clean(value) if value in EMPTY_VALUES: return '' value = value.replace(' ', '').replace('-', '') if not self.r_valid.match(value) or not luhn(value): raise ValidationError(self.error_messages['invalid']) return value
def clean(self, value): if value not in EMPTY_VALUES: value = value.replace(' ', '').replace('-', '') ret = super(FRSIRETField, self).clean(value) if not luhn(ret[:9]): raise ValidationError(self.error_messages['invalid']) return ret
def clean(self, value): super(CreditCardField, self).clean(value) value = value.strip().replace(' ', '') if not luhn(value): raise ValidationError(self.error_messages['invalid']) return value
def clean(self, value): value = super(ILIDNumberField, self).clean(value) if value in EMPTY_VALUES: return u'' match = id_number_re.match(value) if not match: raise ValidationError(self.error_messages['invalid']) value = match.group('number') + match.group('check') if not luhn(value): raise ValidationError(self.error_messages['invalid']) return value
def clean(self, value): value = super(ILIDNumberField, self).clean(value) if value in EMPTY_VALUES: return '' match = id_number_re.match(value) if not match: raise ValidationError(self.error_messages['invalid']) value = match.group('number') + match.group('check') if not luhn(value): raise ValidationError(self.error_messages['invalid']) return value
def clean(self, value): value = super(ILIDNumberField, self).clean(value) if value in EMPTY_VALUES: return u"" match = id_number_re.match(value) if not match: raise ValidationError(self.error_messages["invalid"]) value = match.group("number") + match.group("check") if not luhn(value): raise ValidationError(self.error_messages["invalid"]) return value
def clean(self, value): super(ZAIDField, self).clean(value) if value in EMPTY_VALUES: return u'' if len(value) < 13: raise ValidationError(self.error_messages['invalid']) # strip spaces and dashes value = value.strip().replace(' ', '').replace('-', '') match = re.match(id_re, value) if not match: raise ValidationError(self.error_messages['invalid']) g = match.groupdict() try: # The year 2000 is conveniently a leapyear. # This algorithm will break in xx00 years which aren't leap years # There is no way to guess the century of a ZA ID number d = date(int(g['yy']), int(g['mm']), int(g['dd'])) dob = datetime.datetime.strptime(d,'%y-%m-%d').strftime('%Y-%m-%d') # {YYMMDD} is the date of birth except ValueError: raise ValidationError(self.error_messages['invalid']) if not luhn(value): raise ValidationError(self.error_messages['invalid']) return value # 0 for South Africans and 1 for other citizens c = int(g['end'][0]) if c = 0: return 'South African'
def clean(self, value): ret = super(FRSIRETField, self).clean(value) if not luhn(ret[:9]): raise ValidationError(self.error_messages['invalid']) return ret
def clean(self, value): if value and (len(str(value)) < 13 or len(str(value)) > 16 or not luhn(value)): raise forms.ValidationError(_(u"Please enter in a valid credit card number.")) return super(CreditCardField, self).clean(value)