From: Mitch Jackson Date: Wed, 28 Nov 2018 20:16:32 +0000 (-0500) Subject: RT# 76309 E-Mail validation methods X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=a1cb420e2647d8b78d7169694145c2dd3b660448 RT# 76309 E-Mail validation methods --- diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index fe8fad969..2bffdc377 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -28,6 +28,7 @@ use FS::Msgcat qw(gettext); use NetAddr::IP; # for validation use Data::Dumper; #use FS::Conf; #dependency loop bs, in install_callback below instead +use Email::Valid; use FS::part_virtual_field; @@ -3153,6 +3154,36 @@ sub ut_agentnum_acl { } + +=item ut_email COLUMN + +Check column contains a valid E-Mail address + +=cut + +sub ut_email { + my ( $self, $field ) = @_; + Email::Valid->address( $self->getfield( $field ) ) + ? '' + : "Illegal (email) field $field: ". $self->getfield( $field ); +} + +=item ut_emailn COLUMN + +Check column contains a valid E-Mail address + +May be null + +=cut + +sub ut_emailn { + my ( $self, $field ) = @_; + + $self->getfield( $field ) =~ /^$/ + ? $self->getfield( $field, '' ) + : $self->ut_email( $field ); +} + =item trim_whitespace FIELD[, FIELD ... ] Strip leading and trailing spaces from the value in the named FIELD(s).