Name

regex — value matches regular expression

DESCRIPTION

Allows you to specify a regular expression to match against the supplied value. Useful for many cases where no existing order check is available.

EXAMPLES

Example: Fiscal data

fiscal_data=regex ^\d\d-[A-Z\d]{9}-\d{4}-[A-Z\d]{10}-\d{4}-\d{4}$ "Invalid format"

NOTES

AVAILABILITY

regex is available in Interchange versions:

4.6.0-5.7.0 (git-head)

SOURCE

Interchange 5.7.0:

Source: code/OrderCheck/regex.oc
Lines: 45


# 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: regex.oc,v 1.3 2007-03-30 23:40:48 pajamian Exp $

CodeDef regex OrderCheck 1
CodeDef regex Description Regular expression match
CodeDef regex Routine <<EOR
sub {    
my($ref, $name, $value, $code) = @_;
my $message;

$code =~ s/\\/\\\\/g;
my @code = Text::ParseWords::shellwords($code);
if($code =~ /(["']).+?\1$/) {
  $message = pop(@code);
}

for(@code) {
  my $negate;
  s/^!\s*// and $negate = 1;
  my $op = $negate ? "!~" :  '=~';
  my $regex = qr($_);
  my $status;
  if($negate) {
    $status = ($value !~ $regex);
  }
  else {
    $status = ($value =~ $regex);
  }
  if(! $status) {
    $message = errmsg(
              "failed pattern - %s",
              "'$value' $op $_"
             ) if ! $message;
    return ( 0, $name, $message);
  }
}
return (1, $name, '');
}
EOR

AUTHORS

Interchange Development Group

SEE ALSO

DocBook! Interchange!