How to validate phone number while adding a new customer user

English! place to talk about development, programming and coding
Post Reply
srikanta
Znuny newbie
Posts: 2
Joined: 11 May 2015, 06:56
Znuny Version: OTRS 4

How to validate phone number while adding a new customer user

Post by srikanta »

I am trying to validate the phone number while adding a new customer user to my OTRS system. The phone number should be 10 digits, and it should accept only digits. I have added the following code in add action in Admincustomeruser.pm inside module but its not working:
if ($GetParam{UserMobile} && length($GetParam{UserMobile}) lt 10)
{
$Errors{UserMobileInvalid} = 'test';
$Errors{ErrorType} = 'Invalid mobile number' . 'ServerErrorMsg';
}
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: How to validate phone number while adding a new customer user

Post by reneeb »

Instead of

Code: Select all

if ($GetParam{UserMobile} && length($GetParam{UserMobile}) lt 10)

Code: Select all

if ($GetParam{UserMobile} && length($GetParam{UserMobile}) =~ m{\A[0-9]{10}\z} )
should work
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
pab
Znuny advanced
Posts: 138
Joined: 20 Jan 2011, 11:21
Znuny Version: [...],6.x, Znuny 7
Real Name: Peter
Company: maxence business consulting GmbH
Location: Dormagen

Re: How to validate phone number while adding a new customer user

Post by pab »

Hi,

Maybe it is better to match the field's content, not it's length:

Code: Select all

if ($GetParam{UserMobile} && $GetParam{UserMobile} =~ m{\A[0-9]{10}\z} )
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: How to validate phone number while adding a new customer user

Post by reneeb »

Sure, that's what I had in mind... I never like mondays ;-)
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Post Reply