Solved

numeric and alphanumeric

Posted on 2001-06-22
3
504 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
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAX Wordpress Not Reading Variable 2 58
PHP SMTP authentication 6 28
Special characters in a TCPDF 4 27
How to hide contact form only if no validation errors 4 29
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 look for a specific file type in a local or remote server directory using PHP.

726 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