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