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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_]')