Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error checking in perl

Posted on 2000-04-30
2
Medium Priority
?
133 Views
Last Modified: 2010-03-05
I have got an error check that checks whether a user has entered any data into a field the code is as follows:

if ($FORM_DATA{firstname} eq "") {
      print"Please enter your firstname<BR>";
}

The above code works fine.  I am however wondering if anyone knows how to check if the user has entered digits or alphabetic characters.

I would like an  Incorrect message to display as above if the user types digits into a field where alphabetical characters ahould be and vice versa does anyone have any ideas.

For example a credit card number field should only contain digits and no alphabetical characters, if the user does enter any alphabetical characters then an Incorrect message is displayed.

I have looked in books but can only find error checking for a blank field.

Any help greatly appreciated.

Anne. email:  anne.smith@lineone.net
0
Comment
Question by:annesmith
2 Comments
 
LVL 6

Accepted Solution

by:
christopher sagayam earned 200 total points
ID: 2764110
if ($FORM_DATA{firstname} =~ /[^0-9]/) {
print"firstname must contain ONLY digits<BR>";
}


if ($FORM_DATA{firstname} =~ /[^a-zA-Z]/) {
print"firstname must contain ONLY alphabets<BR>";
}
0
 

Author Comment

by:annesmith
ID: 2764189
Thank you Chris18 for your reply.

Your solution is working. Excellent.

Many Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question