China (cn)

Forms

China(mainland)-specific Form helpers.

class localflavor.cn.forms.CNProvinceSelect(attrs=None)[source]

A select widget providing the list of provinces and districts in People’s Republic of China as choices.

class localflavor.cn.forms.CNPostCodeField(*args, **kwargs)[source]

A form field that validates input as postal codes in mainland China.

Valid codes are in the format of XXXXXX where X is a digit.

class localflavor.cn.forms.CNIDCardField(max_length=18, min_length=15, *args, **kwargs)[source]

A form field that validates input as a Resident Identity Card (PRC) number.

This field would check the following restrictions:
  • the length could only be 15 or 18;
  • if the length is 18, the last character can be x or X;
  • has a valid checksum (only for those with a length of 18);
  • has a valid date of birth;
  • has a valid province.

The checksum algorithm is described in GB11643-1999. See: http://en.wikipedia.org/wiki/Resident_Identity_Card#Identity_card_number

clean(value)[source]

Check whether the input is a valid ID Card Number.

has_valid_birthday(value)[source]

This method grabs the date of birth from the ID card number and test whether it is a valid date.

has_valid_checksum(value)[source]

This method checks if the last letter/digit is valid according to GB11643-1999.

has_valid_location(value)[source]

This method checks if the first two digits in the ID Card are valid province code.

class localflavor.cn.forms.CNPhoneNumberField(*args, **kwargs)[source]

A form field that validates input as a telephone number in mainland China.

A valid phone number could be like: 010-12345678. Considering there might be extension numbers, this could also be: 010-12345678-35.

class localflavor.cn.forms.CNCellNumberField(*args, **kwargs)[source]

A form field that validates input as a cellphone number in mainland China.

A valid cellphone number could be like: 13012345678.

A very rough rule is used here: the first digit should be 1, the second should be 3, 4, 5, 7 or 8, followed by 9 more digits. The total length of a cellphone number should be 11.

Changed in version 1.1: Added 7 as a valid second digit for Chinese virtual mobile ISPs.

Data

localflavor.cn.cn_provinces.CN_PROVINCE_CHOICES = ((u'anhui', u'\u5b89\u5fbd'), (u'beijing', u'\u5317\u4eac'), (u'chongqing', u'\u91cd\u5e86'), (u'fujian', u'\u798f\u5efa'), (u'gansu', u'\u7518\u8083'), (u'guangdong', u'\u5e7f\u4e1c'), (u'guangxi', u'\u5e7f\u897f\u58ee\u65cf\u81ea\u6cbb\u533a'), (u'guizhou', u'\u8d35\u5dde'), (u'hainan', u'\u6d77\u5357'), (u'hebei', u'\u6cb3\u5317'), (u'heilongjiang', u'\u9ed1\u9f99\u6c5f'), (u'henan', u'\u6cb3\u5357'), (u'hongkong', u'\u9999\u6e2f'), (u'hubei', u'\u6e56\u5317'), (u'hunan', u'\u6e56\u5357'), (u'jiangsu', u'\u6c5f\u82cf'), (u'jiangxi', u'\u6c5f\u897f'), (u'jilin', u'\u5409\u6797'), (u'liaoning', u'\u8fbd\u5b81'), (u'macao', u'\u6fb3\u95e8'), (u'neimongol', u'\u5185\u8499\u53e4\u81ea\u6cbb\u533a'), (u'ningxia', u'\u5b81\u590f\u56de\u65cf\u81ea\u6cbb\u533a'), (u'qinghai', u'\u9752\u6d77'), (u'shaanxi', u'\u9655\u897f'), (u'shandong', u'\u5c71\u4e1c'), (u'shanghai', u'\u4e0a\u6d77'), (u'shanxi', u'\u5c71\u897f'), (u'sichuan', u'\u56db\u5ddd'), (u'taiwan', u'\u53f0\u6e7e'), (u'tianjin', u'\u5929\u6d25'), (u'xinjiang', u'\u65b0\u7586\u7ef4\u543e\u5c14\u81ea\u6cbb\u533a'), (u'xizang', u'\u897f\u85cf\u81ea\u6cbb\u533a'), (u'yunnan', u'\u4e91\u5357'), (u'zhejiang', u'\u6d59\u6c5f'))

An alphabetical list of provinces for use as choices in a formfield. http://en.wikipedia.org/wiki/ISO_3166-2:CN http://en.wikipedia.org/wiki/Province_%28China%29 http://en.wikipedia.org/wiki/Direct-controlled_municipality http://en.wikipedia.org/wiki/Autonomous_regions_of_China