diff options
| author | Mitch Jackson <mitch@freeside.biz> | 2018-11-28 15:16:32 -0500 |
|---|---|---|
| committer | Mitch Jackson <mitch@freeside.biz> | 2018-11-28 15:38:16 -0500 |
| commit | 4267c47797189621effba74f0d83f29fadf3e259 (patch) | |
| tree | f14f7cee3e1f8b6f4a91689265433160ca1aa9e5 | |
| parent | 9de321e11b1463bda7d8dc9cfa2c438c66687a4b (diff) | |
RT# 76309 E-Mail validation methods
| -rw-r--r-- | FS/FS/Record.pm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 60e7ff7a9..dfe6f1871 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -25,6 +25,7 @@ use FS::Schema qw(dbdef); use FS::SearchCache; use FS::Msgcat qw(gettext); #use FS::Conf; #dependency loop bs, in install_callback below instead +use Email::Valid; use FS::part_virtual_field; @@ -3360,6 +3361,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). |
