
Business::CN::IdentityCard - Validate the Identity Card NO. in China

use Business::CN::IdentityCard;
my $id = '11010519491231002X'; # a unsure identity card no.
my $idv = new Business::CN::IdentityCard;
if ($idv->validate($id)) { # call the validate_id method
print 'Pass';
print $idv->gender; # the gender of the id, default is *Chinese*
print $idv->gender('EN'); # the English gender: Male|Female
print $idv->birthday; # the birthday of the id, eg: 1975-10-31
print $idv->province; # the province of the id, in Chinese
print $idv->district; # the district of the id, *NOT* suggested
} else {
print $idv->err; # the type of error, details see below
print $idv->errstr; # the error detail
}

It validates the given Identity Card NO., and give some info(including gender, birthday, province and district) of the id.
There is a Chinese document @ http://www.fayland.org/IDCard/Validate.html. It explain the algorithm of how-to validate the Identity Card no.

you can declare the object with the id, such as
my $idv = new Business::CN::IdentityCard($id); $idv->validate;
if the id is provided by new, u can ignore the parameter, otherwise the parameter is needed. if the ID is correct, return 1, otherwise return 0 and u can get the error details. see below.
return the gender of the id owner. default return the Chinese gender, use gender('EN') to get the Female or Male.
return the birthday of the id owner. the format is like YYYY-MM-DD
return the province of the id owner. It's Chinese.
NOT suggested. because it's not perfect and takes memory. of course, use it if needed.
return the type of the error.
the detail of the error

Adam Kennedy - who advises me to change 'China::IdentityCard::Validate' to this.
chunzi - provide the basic of the enhanced version && district detail
joe - fix a regex bug

feel free to report any bugs or corrections.

Fayland <fayland@gmail.com>

Copyright (c) 2005 Fayland All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.