1# Copyright 2005-2007 Interchange Development Group and others 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2 of the License, or 6# (at your option) any later version. See the LICENSE file for details. 7# 8# $Id: length.oc,v 1.3 2007-03-30 23:40:48 pajamian Exp $ 9 10CodeDef length OrderCheck 1 11CodeDef length Description String length 12CodeDef length Routine <<EOR 13sub { 14 my($ref, $name, $value, $msg) = @_; 15 $msg =~ s/^(\d+)(?:\s*-(\d+))?\s*// 16 or return undef; 17 my $min = $1; 18 my $max = $2; 19 my $len = length($value); 20 21 if($len < $min) { 22 $msg = errmsg( 23 "%s length %s less than minimum length %s.", 24 $name, 25 $len, 26 $min) if ! $msg; 27 return(0, $name, $msg); 28 } 29 elsif($max and $len > $max) { 30 $msg = errmsg( 31 "%s length %s more than maximum length %s.", 32 $name, 33 $len, 34 $max) if ! $msg; 35 return(0, $name, $msg); 36 } 37 return (1, $name, ''); 38} 39EOR