How to print only numbers in txtbox?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aditya
Forum Newbie
Posts: 15
Joined: Mon Jan 15, 2007 7:44 am

How to print only numbers in txtbox?

Post by aditya »

Hi

i have one text box . in That text box i would like to print only numbers but not Alphabets . Please send the code in PHP . Urgent Help me please
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Please stop telling us your problems are urgent. Everyone's post is equally important here, and telling us yours is urgent will likely shy people away from helping you. Furthermore, we arn't here to give you solutions to your problems, this is a place of learning.

A simple preg_match() can capture all the numeric characters in a string using the \d (digit) character.

Thats as much help as you'll get from me until you can show that your at least trying.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

$x = range(0,9); $i = str_split($q); $m = null; foreach ($i as $t => $o) if (in_array($o, $x)) $m .= $o;
Post Reply