Merge branch 'master' of https://github.com/jgoodman/Freeside
[freeside.git] / rt / share / html / Elements / ValidateCustomFields
index 539c6f4..713885f 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -81,7 +81,32 @@ while ( my $CF = $CustomFields->Next ) {
         grep defined, @values;
     @values = ('') unless @values;
 
-    foreach my $value( @values ) {
+    for my $value( @values ) {
+        if ($value) {
+            if ( $CF->Type eq 'IPAddress' ) {
+                use Regexp::Common qw(RE_net_IPv4);
+                my $ip = RT::ObjectCustomFieldValue->ParseIP( $value );
+                unless ( $ip ) {
+                    my $msg =
+                      loc( "Input can not be parsed as an IP address" );
+                    $m->notes( ( 'InvalidField-' . $CF->Id ) => $msg );
+                    push @res, $msg;
+                    $valid = 0;
+                }
+            }
+            elsif ( $CF->Type eq 'IPAddressRange' ) {
+                my ( $start_ip, $end_ip ) =
+                  RT::ObjectCustomFieldValue->ParseIPRange($value);
+                unless ( $start_ip && $end_ip ) {
+                    my $msg =
+                      loc( "Input can not be parsed as an IP address range" );
+                    $m->notes( ( 'InvalidField-' . $CF->Id ) => $msg );
+                    push @res, $msg;
+                    $valid = 0;
+                }
+            }
+        }
+
         next if $CF->MatchPattern($value);
 
         my $msg = loc("Input must match [_1]", $CF->FriendlyPattern);