adhirath wcities adhirath wcities - 2 years ago 94
Javascript Question

How to separate house number from full address using javascript

I am fetching address from all over the world and format for the address is different. What I need is to separate house number from rest of the address and return house number as a separate element and rest of the address as a separate using JavaScript or jQuery.
Here is example of address:

Langstrasse 120, Zürich
1314 Grant Street, San Francisco

Answer Source

Try This

var addr = 'Langstrasse 120, Zürich';
var myA = addr.split(/(\d+)/g);

This will give you the House number from the Address and then replace this number with whole address, You will find the address without house number.

var full_address    = addr.replace(myA[1],"");

your myA[1] will be house number and full_address will be address without House number.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download