GDP Posted August 6, 2014 Share Posted August 6, 2014 Hi guys, I've got a regular job where the client is supplying an address field set up as one line. For example; 52 Sanyhils Avenue, Patcham, Brighton, East Sussex, BN1 8UN However, the data needs to be put into two separate boxes for address and postcode. Is there a way to output the data in this manner? ie; Text Box ADDRESS - 52 Sanyhils Avenue, Patcham, Brighton, East Sussex, Text Box POSTCODE - BN1 8UN any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 6, 2014 Share Posted August 6, 2014 This assumes the POSTCODE is always the last 7 characters of your address field. Rule to format the ADDRESS: var text = Field("Address");//Replace with your field name return Left(Trim(text),text.length-7); Removes the last 7 characters (plus extra spaces) and returns the rest of the field. Rule to format the POSTCODE: var text = Field("Address");//Replace with your field name return Right(Trim(text),7); Returns the last 7 characters of the field (after removing extra spaces). Quote Link to comment Share on other sites More sharing options...
GDP Posted August 7, 2014 Author Share Posted August 7, 2014 Hi David, Thanks for the quick reply! UK postcodes can vary from 7 to 8 characters (including spaces) - is there a way to do that? Rather than a fixed 7 character line? Cheers, Pete Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 8, 2014 Share Posted August 8, 2014 (edited) Interesting point. So, a better option might be to look for the last comma in your field and separate the field accordingly. This assumes the POSTCODE is always after the last comma of your address field. (Using Regular Expression, Regex, Regexp) Rule to format the ADDRESS: var address = Field("Address");//Replace with your field name //Remove the text after the last comma var nonpostcode = address.replace(/,[^,]+$/, ""); //Return the text that was not removed return nonpostcode; Rule to format the POSTCODE: var address = Field("Address");//Replace with your field name //Retrieve the text after the last comma var postcode = address.match(/,\s*([^,]+)$/)[1]; //Return the retrieved text return postcode; Credit goes to a little Google-fu and a post that should not be forgotten here. Edited August 8, 2014 by David Miller Quote Link to comment Share on other sites More sharing options...
GDP Posted August 8, 2014 Author Share Posted August 8, 2014 Many thanks for your help on this David - it works a treat! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.