We are sending Address Line1 and Address Line2 for validation.
And when it goes to USPS for validation, after validation it concatenates both address lines in Address Line1.
For instance:
AddressLine1: 20 ROOSEVELT AVE
AddressLine2: apt# 22
After validation it concatenates both the address lines:
AddressLine1: 20 Roosevelt Ave Apt# 209
AddressLine2: null
I want to break the returned Address Line1 as a validated address back into two lines, how can I do this?
The USPS validation is reformatting the text beyond just concatentating the two lines. I don't know what kind of reformatting may be involved for different types of addresses, but in your example the only difference seems to be that it has changed from upper to mixed case, and the apartment number has changed. I have no suggestions on how to handle a change to the information (like the number changing), but if only the upper/lower case changes you can do something like the following:
// you specified both Java AND JavaScript; I've picked JavaScript
var originalLine1 = "...",
originalLine2 = "...";
// somehow call USPS validation to set the following:
var validatedLine1 = "...",
validatedLine2 = "...",
validationPassed = true || false;
// now, did validation pass?
if (validationPassed) {
// if we can match the old line 1 with the left-hand side
// of the new line 1, and we're not going to be overwriting
// a non-null value in the new line 2 then split the new line 1
if (validatedLine2 === null &&
originalLine1.toLowerCase()
=== validatedLine1.substr(0,originalLine1.length).toLowerCase()) {
validatedLine2 = validatedLine1.substr(originalLine1.length);
validatedLine1 = validatedLine1.substr(0, originalLine1.length);
}
// do something with the results
}
Having said that, what is the purpose of calling the USPS validation? If it modifies the text but otherwises passes validation maybe you should just use the modified version since presumably that follows USPS's addressing standards?