如何从JavaScript中的给定字符串获取街道名称,城市,州和邮政编码

时间:2015-06-05 20:22:04

标签: javascript

2224 Mission Street San Francisco CA 94110

字符串应拆分为:

StreetName:2224 Mission Street

城市:旧金山

州:CA

zip:94110

1 个答案:

答案 0 :(得分:0)

var address = ("2224 Mission Street San Francisco CA 94110").trim().replace(" ",""),
zip = address.substring(address.length-5, address.length), //provided zip in at the end of the string and it's 5 digit.
state = address.substring(address.length-7, address.length-5)// provided state contains two characters;

但是有没有任何规则来划分街道和市2005?