How to resolve card number length error in Koha

The cardnumber length system preference in koha seems to be ignored since the values are hard coded in the system. However, since it is open-source system, we can dissect it, open it up and set up things the way we want.
This is a very simple and effective solution to this very notorious problem. Since it is so simple you will only need to locate the file If you used koha standard installation method, then this will be in :


At around line number 1252, you will see the method get_cardnumber_length below:

sub get_cardnumber_length {
    my ( $min, $max ) = ( 0, 16 ); # borrowers.cardnumber is a nullable varchar(16)
    $min = 1 if C4::Context->preference('BorrowerMandatoryField') =~ /cardnumber/;
    if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) {
        # Is integer and length match
        if ( $cardnumber_length =~ m|^\d+$| ) {
            $min = $max = $cardnumber_length
                if $cardnumber_length >= $min
                    and $cardnumber_length <= $max;
        # Else assuming it is a range
        elsif ( $cardnumber_length =~ m|(\d*),(\d*)| ) {
            $min = $1 if $1 and $min < $1;
            $max = $2 if $2 and $max > $2;

    return ( $min, $max );

On the 2nd line in the code above, change the values in ( 0, 16 )to whatever you want. Just bear in mind that 0 is the minimum and 16 is the maximum length.
The largest number you can set however, is 255 which is set on the borrowers table in koha’s database.

This should resolve the problem and if not, check again to confirm that you are not editing the wrong file!

Otuoma Sanya

Otuoma Sanya is a full-time systems librarian, tech enthusiast and writer. His areas of interest are data mining, institutional repositories, library automation and web development using python Django.

Leave a Reply