def check_input_data(cls, data, check_flag): flag = 0 for item in data.items(): if item[0].endswith('_msg'): item[1] = '' if is_none_or_empty_or_blank(data.get('bank_account_name')): data['bank_account_name_msg'] = cls.__cannot_be_empty flag = 1 if is_none_or_empty_or_blank(data.get('bank_account_no')): data['bank_account_no_msg'] = cls.__cannot_be_empty flag = 1 else: bank_account_no = data['bank_account_no'].replace(' ', '') if not bank_account_no.isdigit(): data['bank_account_no_msg'] = cls.__must_be_digit flag = 1 elif len(bank_account_no) < 15 or len(bank_account_no) > 22: data['bank_account_no_msg'] = cls.__invalid_length flag = 1 if is_none_or_empty(data.get('bank_account_pwd')): data['bank_account_pwd_msg'] = cls.__cannot_be_empty flag = 1 else: if not data['bank_account_pwd'].isdigit(): data['bank_account_pwd_msg'] = cls.__must_be_digit flag = 1 elif len(data['bank_account_pwd']) != 6: data['bank_account_pwd_msg'] = cls.__invalid_length flag = 1 if check_flag != 0: if is_none_or_empty_or_blank(data.get('cert_id')): data['cert_id_msg'] = cls.__cannot_be_empty flag = 1 elif check_flag == 1: # 身份证 cert_id = data['cert_id'].replace(' ', '') if not is_valid_id_card_num(cert_id): data['cert_id_msg'] = u'证件号无效' flag = 1 else: # 组织机构号码 cert_id = data['cert_id'].replace(' ', '') if not re.compile('[0-9]+$').match(cert_id): data['cert_id_msg'] = u'证件号无效' flag = 1 return flag
def clean_identification_card_number(self): data = self.cleaned_data['identification_card_number'] if not is_valid_id_card_num(data): raise forms.ValidationError(u'身份证号码不合法。') return data