Re: Check input against list

From: Date: Tue, 01 Aug 2000 18:00:52 +0000
Subject: Re: Check input against list
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-9498@lists.php.net to get a copy of this message
> I have a couple input fields that require ISO state and country codes. > > Is there some way to check that an input string is one of N possibilities, > where N is a large-ish number? > or do I have to do the ugly, obvious method like > > if (($ST <> "AK") or ($ST <> "AL")......... barf..) Something like this? $States = array("CA", "AZ", "HI"); if (isset($States[$UserEnteredState])) echo "Yes, we have service there!"; in_array() can be used very similarly. I'd recommend against letting the user enter those codes, however. I already had a MySQL table with the ISO country code/full name data (which was referenced by a couple other tables) and so it was very simple to generate a <SELECT> on the input form, which had the side benefit of reducing the validation logic to "did the user pick one?". Chris

« previous php.general (#9498) next »