• Resolved stevobaggio

    (@stevobaggio)


    Hello,

    I was wondering if there was any way to restrict which postcodes are allowed in the Distance operations? I need one field to only a restricted number of postcodes and another field to allow only UK postcodes.

    I am using the Platinum plugin, but do not have my site up and running yet (the quotation system I’m using CFF to build is the core of the site).

    Many thanks.

    https://www.ads-software.com/plugins/calculated-fields-form/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    If the postcode fields are: fieldname1, and fieldname2, and the equation associated to the calculated field is:

    DISTANCE(fieldname1, fieldname2, 'mi', 'DRIVING')

    It should be modified as follows:

    (function(){
    var f1 = fieldname1,
        f2 = fieldname2,
        valid_postcode = function (postcode) {
        postcode = postcode.replace(/\s/g, "");
        var regex = /^[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}$/i;
        return regex.test(postcode);
        };
    
    if( AND(f1,f2))
    {
       if( valid_postcode(f1) && valid_postcode(f2))
       {
          return DISTANCE(f1,f2,'mi', 'DRIVING');
       }
       else
       {
          return 'Invalid Postcode';
       }
    }
    else
    {
    return '';
    }
    })()

    This code is not part of the plugin’s code, so, if you need additional help, you should request a custom coding service through our private support page:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter stevobaggio

    (@stevobaggio)

    Thank you so much! I’ll get in touch via that link if I need anything else!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limiting postcodes’ is closed to new replies.