I agree that splitting the city state is probably more complicated than it's worth though.
If you suggest otherwise, how do we know that they can spell their street correctly?
If you give someone separate fields for 'city' and 'state' you have some chance of figuring out where they are located if they type 'Washington' into one of those fields. If you ask them just for 'city, state', some people will understand that as 'city or state' and just type 'Washington', and you have no idea what they mean. The example I gave before, LA, is an example of a city which shares its name with a state abbreviation.
An anecdote for you: I was once working with UK callcentre system which had a form for callcentre staff to update customer contact addresses. UK postcodes are combinations of letters and numbers, and certain letters are excluded from certain positions to prevent ambiguous handwritten letterforms causing confusion. I naively implemented strict postcode validation, thinking it would help catch data entry errors. What actually happened was that we ended up, in a significant number of cases, telling people that the postcode that they had been using as part of their address for decades was not, in fact their postcode - it couldn't be because it was an invalid postcode. This made the customers quite cross, and we had to change it.
Do you want your validation message to be the one to break it to some eighty year old guy that Nebraska is actually NE, not NB any more?
Considering the Internets is a really really big place (not just America), that statement is rather quite false.
This is a bad assumption. What you should do is throw away commas, split along whitespace, and then see if the last element split is a valid state or territory.
Because some lazy guy will type "new orleans la" and just ruin your day.
I know, this isn't a particularly difficult thing to work around, but I was amused that you replaced one bad assumption with another.
We could always start taking from the back and doing look ups until we have a match or we finish the string.
Is "." a state? How about "75254"?
Hell, just let the user write in the postal code and use their IP address to match it with the country of residence. They can put any number in there and you can match it to some location. No states. No assumptions. Well, beyond the one about IP address being accurate, I guess.
Quick, spell the state that starts with "M" and ends in "ets"! How about "M"-"pi"? "T"-"see"?
I know, it's almost trivial to guess at misspellings. But that's just another piece of code you have to write.
But the point is---code to check for misspellings already exists.
[http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-b...]
2. There are exactly 50 states, so 50 names and 50 abbreviations. You are expecting the data in "City, State" format, so you parse the form in Javascript when the user finishes typing. If the data after the comma matches one of 100 strings, turn the form green, otherwise turn the box red.
3. Put the expected representation in the label. Parse the form as the user is typing, and replace the date with your interpretation when the box loses focus ("01/23/12" => "January 23, 2012") Turn the box red if the month is > 12 or the day > 31.
If the user has Javascript disabled, display a verification screen after the form is submitted.