Solved

Error checking in perl

Posted on 2000-04-30
2
127 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Rename file based on contents in the file? 3 108
perl script to check whether folder contains any files 5 110
perl: Cleaning meta tags using RegEX 12 94
Export Variables in Perl 3 125
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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

752 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