Solved

Error checking in perl

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
collecting information 2 184
perl script to check whether folder contains any files 5 92
create a gui in perl 3 98
read an xml file in perl 2 50
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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

828 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