Solved

numeric and alphanumeric

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

691 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