Solved

numeric and alphanumeric

Posted on 2001-06-22
3
501 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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Richard Coffre earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
You're welcome
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now