$data =~ s/\s+/ /g; # Remove extra spaces to nothing $data =~ s/ +//g; #### $length = length( $data ); if ( ! $length ) { # empty string if ( $obligatory ) { bail_out( "Obligatory field not filled in" ); } else { return; } } if ( $data =~ /([^-\@\w. ])/) { bail_out( "Bad character: $1 -- Only alphanumerics and -@. allowed" ); } if ( $numeric and $data =~ /[^\d]/ ) { bail_out( "Non-numeric character(s) in numeric field" ); } if ( $min and $length < $min ) { bail_out( "too short" ); } if ( $max and $length > $max ) { bail_out( "too long" ); } return $data;