RE: [PHP] limit form input digits

From: Date: Thu, 08 May 2003 00:06:32 +0000
Subject: RE: [PHP] limit form input digits
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146763@lists.php.net to get a copy of this message
> I'm trying to limit to 99 the amount of times this prints ; > > if (ereg ("([^0-9]{2})", $incre)) { > echo "bad input"; > } else { > echo "Printing now ...<br>"; > } > > Reading the manual and the comments I thought the {2} would do that, > but it doesn't. I have set the form field size to two but that isn't > working > either, you can still put more than two numbers in the field even though > they don't show. The {2} does keep letters out but how can I limit the > input to two digits ? What's wrong with: If($incre > 0 && $incre <= 99) { echo "printing now... "; } else { echo "bad input"; } You don't need regular expressions for this. You could even add $incre = (int)$incre; before that to ensure $incre is an integer. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#146763) next »