Link to home
Start Free TrialLog in
Avatar of n8dog
n8dog

asked on

ZIP Code 5 Digit Value?

How do i validate a ZIP variable to ensure it's a 5 digit value?

-n
ASKER CERTIFIED SOLUTION
Avatar of callrs
callrs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of callrs
callrs

That prints 1 if $zip is 5 digits, prints 0 otherwise
It's
<?php
$zip="01234";
if (preg_match("/^\d{5}$/", $zip, $match) === 1)
        echo 'Match';
else
        echo 'No Match';

?>
TeRReF, your solution is exactly what callrs said. What's the point in capturing the match when it's an all-or-nothing pattern?
Avatar of n8dog

ASKER


ended up using


$varlen = strlen($var)

thanks guys
In that case, make sure you also use ctype_digit($var) to check that $var contains only numeric characters.
Avatar of n8dog

ASKER

excellent.. thanks for that addition!
Yes, thanks!  : )
A+

humeniuk, if you see this, please re-open question to allow HackneyCab a points share
(and this too if you can hehe http:Q_21982002.html)