Link to home
Start Free TrialLog in
Avatar of brok21k
brok21k

asked on

perl regexp BASIC

 Im new with perl. I creating a registration page, my problem lies in validating input data (which i want to acheive through perl)."if($fields[$i] !~ /[aA-zZ0-9]+/)"
I basicly , only want to only allow numeric and char, to be allowed, but it still accepts *-()" ect..

Can any one help.

i.e.
      #Post-code
      if($i == 3)
      {
         
           if($fields[$i] !~ /[aA-zZ0-9]+/)
          {
             
              $errors1[$i] = 6;
           }
           if ($fields[$i] == "")
           {
              $errors1[$i] = 0;
           }
     
view this page for information.
http://johnboshelle.tripod.com/cgi-bin/cwk1.pl
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chani
Chani

brok21k's code will technically match any line that does not contain at least one of the characters in his character class (all strange characters would not work, but if you had one valid character in the field, it would - regardless of what else is in the string).  

ozo's code will match any line that does not start and end w/ one of the characters in his character class (this does not take the newline at the end or spaces into account - one long word would work, but a sentence would not match that).

Try this:
---
unless ($fields[$i] =~ /[\W\S]/) {
---
('[\W\S] == [^ \r\t\n\fa-zA-Z0-9_]')