Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error checking in perl

Posted on 2000-04-30
2
Medium Priority
?
131 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

715 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