Hi all- newbie here.
I could be a regular by the time my CIW course is finished.
I have a query about data validation which I'm hoping will be bread and butter for someone. I've been asked to write a perl program to request input and check the response. The first of these is to ask for a 4 digit number and ensure it meets the criteria. This is something I thought would be easy but in practice it is not working.
I've posted my code below. It does ensure that only 4 digits are used and that the inout is numeric. It does not though stop a user from typing more than 4 digits:
print ("Please enter your 4 digit customer reference:\n");
$custRef =<STDIN>;
chomp($custRef);
while ($custRef !~ m/\d{4,4}/)
{
print("There was an error, try again.\n\n");
print ("Please enter your 4 digit customer reference:\n");
$custRef =<STDIN>;
chomp($custRef);
}
I could be a regular by the time my CIW course is finished.
I have a query about data validation which I'm hoping will be bread and butter for someone. I've been asked to write a perl program to request input and check the response. The first of these is to ask for a 4 digit number and ensure it meets the criteria. This is something I thought would be easy but in practice it is not working.
I've posted my code below. It does ensure that only 4 digits are used and that the inout is numeric. It does not though stop a user from typing more than 4 digits:
print ("Please enter your 4 digit customer reference:\n");
$custRef =<STDIN>;
chomp($custRef);
while ($custRef !~ m/\d{4,4}/)
{
print("There was an error, try again.\n\n");
print ("Please enter your 4 digit customer reference:\n");
$custRef =<STDIN>;
chomp($custRef);
}