I am trying to make a dynamic address builder to be used in combination with GMap Geocoder.
My code is like the following:
HTML
<input type="text" class="address" />
<input type="text" class="city" />
<input type="text" class="state" />
<input type="text" class="zipCode" />
<input type="text" class="country" />
JavaScript
$('.address, .city, .state, .zipCode, .country').blur(
function()
{
var address = '';
address += $('.address').val() + ', ';
address += $('.city').val() + ', ';
address += $('.state').val() + ', ';
address += $('.zipCode').val() + ', ';
address += $('.country').val();
console.log(address);
}
);
The problem now :
When I blur the address field I am getting the following in my console:
MyAddress, , , ,
also, in some case (at least for my area) there are two names for the same location and we use coma to separate them. In example the address can become something like that:
MyAddress, MySecondAddress, Cityname, State, zipCode, Country
The Question:
while the address is builded automatically, how can I remove the remaining commas from the address string by using regex?
address?