Solved

Error checking in perl

Posted on 2000-04-30
2
120 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 50 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now