China (cn)


China(mainland)-specific Form helpers.


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


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, min_length=15, **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:


Check whether the input is a valid ID Card Number.


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


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


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

Data = (('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.