Hi there,
This is similar to a previous post but I need help understanding and streamlining a bit of code. The purpose of the code below is to validate that the user enters a street address in $a using letters, numbers, single spaces and periods. I was trying to write a single matching statement in the if line but could not do it. The only solution I could come up with is what I came up with below.
Code:
if ($a !~ m/^[A-Za-z\d\.\s]+$/ || $a =~ m/\s{2,}/) {
$error="Y";
$msg = $msg . "<p>The Address field must contain only letters, numbers";
$a =~ s/\s/ \;/g; #place spaces in string if they are there-for error.
$msg = $msg . ", single spaces and periods(.) - \"$a\" is invalid.</p>\n";
} #end if
Is it possible to make it so that you do not have to use the or(||) statement to account for multiple spaces within the string contained by $a. I would have thought that you could have melded the 2 statements in the if line together to account for everything but I could not do it. Can someone please help if it can be done.
I want "123 Barneby Rd." to pass (no error) but I want an error to flag when there is more than one space entered like if there were 2 or 3 spaces between 123 and Barneby like:
Code:
123 Barneby Rd.
123 Barneby Rd.