ramachandrajr has asked for the wisdom of the Perl Monks concerning the following question:

front end

<li>  <input type='text' name='mob' placeholder='Phone Number'></li>

Back end

my $mob = $q->param("mob"); $mob =~ s/[:;$%&@<>?]//gi; #dbi logins here print "Content-Type: text/html\n\n"; print "<html><body>\n"; print $mob; print "</html></body>\n";

Replies are listed 'Best First'.
Re: Unable to pass 0 number through form with CGI DBI backend
by marto (Cardinal) on Sep 12, 2015 at 10:45 UTC

    Consider:

    use strict; use warnings; my $mob = '070222000123'; print "$mob\n"; $mob =~ s/[:;$%&@<>?]//gi; print "$mob\n";

    Output

    070222000123 7222123

    You strip them out before you do anything database related. Basic debugging can include simply printing data to the screen so you know that it is what you expect it to be. Basic debugging checklist.

      thats okay but in future if we may need contact info from db we r not gonna get the right number

        Consider using a list of allowed characters with negation.

        $mob =~ s/[^0-9-]//gi;
        poj

        Sure, if you throw away data before inserting it into your database, when you query the database in future the data in quesiton won't be there. I'm not sure what you expect. Likely your post does not properly describe your problem.

Re: Unable to pass 0 number through form with CGI DBI backend
by shmem (Chancellor) on Sep 12, 2015 at 21:35 UTC

    As marto pointed out, the character class of your data laundering substitution is not what you think it to be.

    perl -le 'print $%' 0

    See perlvar. Escape the $ in your character class with a backslash.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'