Jump to content

Ignore Postcode and Using Just the postcode


GDP

Recommended Posts

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. :)

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by David Miller
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...