You are viewing limited content. For full access, please sign in.

Question

Question

Using Javascript to pattern match then pass matched data to another field within same form

asked on April 9, 2014 Show version history

 

Client enters addresses in a standard format across most systems so in keeping with that format we have a field on an early form that collects address in this format – Street Name Street Number (Main Street 2134).  In a later form we need to do a lookup based on address but need Street Number Street Address as the query submission.  So, as still a beginner to JavaScript I need help with doing pattern matching then flipping street number and address and passing it to a new field on the same form to do the lookup.  Below is the Javascript that I have attempted with no luck so far and obviously may be going the wrong direction on this.  Original is the class assigned to the address field that contains the data as Street Address Street Number.  Lookup is the class assigned to the field that needs to be Street Number Street Address and will be submitted as the lookup data.  Thanks for the help.  

 

$(document).ready(function () {
var site = ('.original input');
var newadd = site.replace(/(\D*)(\d*)/, "$2, $1");
    $('.lookup input').val(newadd);
 });

mod edit: placed javascript code in a code-block for readability

0 0

Answer

APPROVED ANSWER
replied on April 9, 2014

I'm not entirely sure what your JavaScript is attempting to do. However, I would strongly suggest against attempting to do string manipulation on complete addresses. There are way too many variations and gotchas when it comes to processing addresses. Instead, you might break apart the address into Address Number and Street Name from the start. The sites that allow you to enter both in the same field are either not concerned about validating too deeply, or have powerful address validation systems backing them up.

2 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.