Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a text box for City, State or Zip. 1

Status
Not open for further replies.

fooobee

Technical User
Nov 13, 2003
33
US
Does anyone have a code sample on how I can use a text box for location (City, State or Zip). I need to determine what has been entered and then parse/pass the values to a webservice and/or search query. An example would be how CareerBuilder does it on their homepage.

Thanks.
 
It shouldn't be hard.

U.S. ZIP codes are a 5-digit number optionally followed by a dash and a four-digit number.
States have two letters.
Anything else could be assumed to be a city name.

Using a test form like:
Code:
<html><body>
<form method="post" action="/test_csz.php">
<input type="text" name="value"><input type="submit">
</form></body></html>

Maybe something along the lines of:
Code:
<?php
if (isset($_POST['value']))
{
	if (preg_match ('/^\d{5}(-\d{4})?$/', $_POST['value']))
	{
		print 'ZIP code';
	}
	else
	{
		if (preg_match ('/^[a-z]{2}$/i', $_POST['value']))
		{
			print 'State abbreviation';
		}
		else
		{
			print "assuming it's a city name";
		}
	}
}
?>
will do the trick


Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top