?
Solved

numeric and alphanumeric

Posted on 2001-06-22
3
Medium Priority
?
507 Views
Last Modified: 2008-02-26
Hi

I looked for this in the PHP manual on PHP.net, but I don't find what I'm looking for (maybe I looked over it).

Basically, what I need is a way to identify whether or not a submitted value contains alphanumeric characters.  It would be even better if those characters could be stripped from the string.

For example, when a user fills in a form field and enters "dfdg2435", the script will return an error because only numbers are allowed.  If it could also remove the "dfdg" part, that would be very nice.

I can always search a string for characters with for instance strstr(), and then even remove the string, but that obviously is no practical solution if you've got a whole collection of ASCII (and other) characters to deal with.

Any suggestions?

Thanks!
0
Comment
Question by:IconMan7
[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
3 Comments
 
LVL 1

Accepted Solution

by:
Richard Coffre earned 200 total points
ID: 6217985
Hi,

To identify if a string is a numeric or not, you can use is_numeric().

If false you can scan the string and rebuild another one without the letters and other special characters.

Hope it helps.

0
 
LVL 3

Author Comment

by:IconMan7
ID: 6218094
Yup.  That works perfectly.
I'll try to figure out how to best replace the alphanumeric stuff, but it's not essential.

Thanks!!
0
 
LVL 1

Expert Comment

by:Richard Coffre
ID: 6218133
You're welcome
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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