1package Regexp::Common::SEN;
2
3use 5.10.0;
4
5use strict;
6use warnings;
7no  warnings 'syntax';
8
9use Regexp::Common qw /pattern clean no_defaults/;
10
11our $VERSION = '2017060201';
12
13=begin does_not_exist
14
15sub par11 {
16    my $string = shift;
17    my $sum    = 0;
18    for my $i (0 .. length ($string) - 1) {
19        my $c = substr ($string, $i, 1);
20        $sum += $c * (length ($string) - $i)
21    }
22    !($sum % 11)
23}
24
25=end does_not_exist
26=cut
27
28# http://www.ssa.gov/history/ssn/geocard.html
29pattern name   => [qw /SEN USA SSN -sep=-/],
30        create => sub {
31            my $sep = $_ [1] {-sep};
32            "(?k:(?k:[1-9][0-9][0-9]|0[1-9][0-9]|00[1-9])$sep"   .
33                "(?k:[1-9][0-9]|0[1-9])$sep"                     .
34                "(?k:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|"     .
35                                         "00[1-9][0-9]|000[1-9]))"
36        },
37        ;
38
39=begin does_not_exist
40
41It's not clear whether this is the right checksum.
42
43# http://www.google.nl/search?q=cache:8m1zKNYrEO0J:www.enschede.nl/nieuw/projecten/aanbesteding/integratie/pve%2520Bijlage%25207.5.doc+Sofi+nummer+formaat&hl=en&start=56&lr=lang_en|lang_nl&ie=UTF-8
44pattern name   => [qw /SEN Netherlands SoFi/],
45        create => sub {
46            # 9 digits (d1 d2 d3 d4 d5 d6 d7 d8 d9)
47            # 9*d1 + 8*d2 + 7*d3 + 6*d4 + 5*d5 + 4*d6 + 3*d7 + 2*d8 + 1*d9
48            # == 0 mod 11.
49            qr /([0-9]{9})(?(?{par11 ($^N)})|(?!))/;
50        }
51        ;
52
53=end does_not_exist
54=cut
55
561;
57
58__END__
59
60=pod
61
62=head1 NAME
63
64Regexp::Common::SEN -- provide regexes for Social-Economical Numbers.
65
66=head1 SYNOPSIS
67
68 use Regexp::Common qw /SEN/;
69
70 while (<>) {
71     /^$RE{SEN}{USA}{SSN}$/    and  print "Social Security Number\n";
72 }
73
74
75=head1 DESCRIPTION
76
77Please consult the manual of L<Regexp::Common> for a general description
78of the works of this interface.
79
80Do not use this module directly, but load it via I<Regexp::Common>.
81
82=head2 C<$RE{SEN}{USA}{SSN}{-sep}>
83
84Returns a pattern that matches an American Social Security Number (SSN).
85SSNs consist of three groups of numbers, separated by a hyphen (C<->).
86This pattern only checks for a valid structure, that is, it validates
87whether a number is valid SSN, was a valid SSN, or maybe a valid SSN
88in the future. There are almost a billion possible SSNs, and about
89400 million are in use, or have been in use.
90
91If C<-sep=I<P>> is specified, the pattern I<P> is used as the
92separator between the groups of numbers.
93
94Under C<-keep> (see L<Regexp::Common>):
95
96=over 4
97
98=item $1
99
100captures the entire SSN.
101
102=item $2
103
104captures the first group of digits (the area number).
105
106=item $3
107
108captures the second group of digits (the group number).
109
110=item $4
111
112captures the third group of digits (the serial number).
113
114=back
115
116=head1 SEE ALSO
117
118L<Regexp::Common> for a general description of how to use this interface.
119
120=head1 AUTHORS
121
122Damian Conway and Abigail.
123
124=head1 MAINTENANCE
125
126This package is maintained by Abigail S<(I<regexp-common@abigail.be>)>.
127
128=head1 BUGS AND IRRITATIONS
129
130Bound to be plenty.
131
132For a start, there are many common regexes missing.
133Send them in to I<regexp-common@abigail.be>.
134
135=head1 LICENSE and COPYRIGHT
136
137This software is Copyright (c) 2001 - 2017, Damian Conway and Abigail.
138
139This module is free software, and maybe used under any of the following
140licenses:
141
142 1) The Perl Artistic License.     See the file COPYRIGHT.AL.
143 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
144 3) The BSD License.               See the file COPYRIGHT.BSD.
145 4) The MIT License.               See the file COPYRIGHT.MIT.
146
147=cut
148