Name

natural — number is a natural number

DESCRIPTION

Verification of the form field value succeeds if the passed value is a natural number, greater than zero.

EXAMPLES

Example: Natural number check

FORM_FIELD_NAME=natural

Example: Natural number check, displaying a custom error message

FORM_FIELD_NAME=natural "Number is not a natural number"

NOTES

Up to Interchange 5.5.2, there was a problem in implementation of this order check which allowed negative values and zero to pass as valid.

AVAILABILITY

natural is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/OrderCheck/natural.oc
Lines: 30


# 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.
# 
# $Id: natural.oc,v 1.4 2008-04-28 12:08:38 docelic Exp $

CodeDef natural OrderCheck
CodeDef natural Description Natural number
CodeDef natural Routine <<EOR
sub {
my ($ref, $name, $value, $code) = @_;

if ($value and $value > 0 and "$value" eq int($value)) {
  return (1, $name, '');
}

$code =~ s/\\/\\\\/g;
$code =~ s/^\s*(["'])(.+?)\1$/$2/;

if ($code =~ /\S/) {
  return (0, $name, $code);
} else {
  return (0, $name, 'no natural number');
}
}
EOR


AUTHORS

Interchange Development Group

SEE ALSO

DocBook! Interchange!