NAME
Business::CN::IdentityCard - Validate the Identity Card NO. in China
SYNOPSIS
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
}
DESCRIPTION
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.
METHOD
- new
-
you can declare the object with the id, such as
my $idv = new Business::CN::IdentityCard($id); $idv->validate;
- 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.
- gender
-
return the gender of the id owner. default return the Chinese gender, use gender('EN') to get the Female or Male.
- birthday
-
return the birthday of the id owner. the format is like YYYY-MM-DD
- province
-
return the province of the id owner. It's Chinese.
- district
-
NOT suggested. because it's not perfect and takes memory. of course, use it if needed.
- err
-
return the type of the error.
- LENGTH
-
if the length of the id is not 15 or 18.
- BIRTHDAY
-
if the birthday is not a normal date.
- PROVINCE
-
no such province code. :)
- DISTRICT
-
what district? I haven't heard that before.
- POSTFIX
-
the last digit is definitely faked.
- errstr
-
the detail of the error
CREDIT
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
BUGS
feel free to report any bugs or corrections.
AUTHOR
Fayland <fayland@gmail.com>
COPYRIGHT
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.