Simply function that validate user's input.
#!/usr/bin/perl -w use strict; # Type: CGI # Usually I use CGI.pm, but sometimes when I just want to validate +data from users I use these two functions : # get_param() # validate_form() # # Tested on textfields and password_fields print "Content-type: text/html; charset=iso-8859-1\n\n"; my %data = get_param(); validate_form(\%data); # I added this line of code to display results print $_." ----- ".$data{$_}."<br/>" foreach keys %data; ############################### # function: validate_form() # ############################### # ERROR when: # # - some field's are empty. User didn't fill them # ( +for example password or login) # - password and re-password are not the same sub validate_form { my $data = shift; foreach (keys %$data) { print "EMPTY FIELD !<br/>" if (!$data->{$_}); } # simply check values that are important for us print "WRONG PASSWORD !<br/>"if ($data->{'password'} !~ /^$data->{ +'re-password'}$/); } ########################### # function: get_param() # ########################### # function get all parameters (name - value) from form # It returns hash ('name' => 'value') # # When user enter ' ' [space] function changes it to '_'. # For example: # Nick: This is my nick # (function change it to This_is_my_nick) # It also change %40 to @ # # ERROR when: # # - user enter different thing than [a-zA-Z0-9-_] sub get_param { my $params = <>; my $err = "WARNING: You can use only numbers and letters a-z A-Z<br +/>"; $params =~ s/\+/_/g; $params =~ s/%40/@/g; # you can use chr() to change hex + print $err if $params =~ /%/g; return split /&|=/, $params; }

In reply to CGI: check Form input by pro7agon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.