1 package FS::cust_main::NationalID;
5 use Date::Simple qw( days_in_month );
8 install_callback FS::UID sub {
12 sub set_national_id_from_cgi {
13 my( $self, $cgi ) = @_;
17 if ( my $id_country = $conf->config('national_id-country') ) {
18 if ( $id_country eq 'MY' ) {
20 if ( $cgi->param('national_id1') =~ /\S/ ) {
21 my $nric = $cgi->param('national_id1');
23 if ( $nric =~ /^(\d{2})(\d{2})(\d{2})\-?(\d{2})\-?(\d{4})$/ ) {
24 my( $y, $m, $d, $bp, $n ) = ( $1, $2, $3, $4, $5 );
25 $self->national_id( "$y$m$d-$bp-$n" );
27 my @lt = localtime(time);
28 my $year = ( $y <= substr( $lt[5]+1900, -2) ) ? 2000 + $y
30 $error ||= "Illegal NRIC: ". $cgi->param('national_id1')
31 if $m < 1 || $m > 12 || $d < 1 || $d > days_in_month($year, $m);
32 #$bp validation per http://en.wikipedia.org/wiki/National_Registration_Identity_Card_Number_%28Malaysia%29#Second_section:_Birthplace ? seems like a bad idea, some could be missing or get added
34 $error ||= "Illegal NRIC: ". $cgi->param('national_id1');
36 } elsif ( $cgi->param('national_id2') =~ /\S/ ) {
37 my $oldic = $cgi->param('national_id2');
40 # can you please remove validation for "Old IC/Passport:" field, customer
41 # will have other field format like, RF/123456, I/5234234 ...
42 #if ( $oldic =~ /^\w\d{9}$/ ) {
43 $self->national_id($oldic);
45 # $error ||= "Illegal Old IC/Passport: ". $cgi->param('national_id2');
49 $error ||= 'Either NRIC or Old IC/Passport is required';
53 warn "unknown national_id-country $id_country";
55 } elsif ( $cgi->param('national_id0') ) {
56 $self->national_id( $cgi->param('national_id0') );