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 would grab 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 = (('anhui', '安徽'), ('beijing', '北京'), ('chongqing', '重庆'), ('fujian', '福建'), ('gansu', '甘肃'), ('guangdong', '广东'), ('guangxi', '广西壮族自治区'), ('guizhou', '贵州'), ('hainan', '海南'), ('hebei', '河北'), ('heilongjiang', '黑龙江'), ('henan', '河南'), ('hongkong', '香港'), ('hubei', '湖北'), ('hunan', '湖南'), ('jiangsu', '江苏'), ('jiangxi', '江西'), ('jilin', '吉林'), ('liaoning', '辽宁'), ('macao', '澳门'), ('neimongol', '内蒙古自治区'), ('ningxia', '宁夏回族自治区'), ('qinghai', '青海'), ('shaanxi', '陕西'), ('shandong', '山东'), ('shanghai', '上海'), ('shanxi', '山西'), ('sichuan', '四川'), ('taiwan', '台湾'), ('tianjin', '天津'), ('xinjiang', '新疆维吾尔自治区'), ('xizang', '西藏自治区'), ('yunnan', '云南'), ('zhejiang', '浙江'))

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