Support » Plugin: Calculated Fields Form » Help with string

  • Resolved Fabbstar

    (@fabbstar)


    Hey!

    I hope all’s well?

    I was wondering if you could help with a quick function question…I have the below formula in a calculated field, which looks up whether a postcode field contains the letters ‘E1’, and if so, return a value:

    if( IN(fieldname83,[‘E1’]) ) return ‘30.00’;

    This works great if the user enters ‘E1’ into the postcode field, however, if the user enters the whole postcode i.e. E1 2AA, then the formula doesn’t work.

    Am I using the correct formula? I am looking for the JS to check if the field contains E1, not if the field only contains these characters.

    Many thanks,
    S

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

    (@codepeople)

    Hello @fabbstar

    The preferred solution here would be use regular expressions, as follows:

    
    if( /E1/i.test(fieldname83) ) return '30.00';
    

    Best regards.

    Fabbstar

    (@fabbstar)

    Hi!

    Thank you so much for the reply and suggestion. It works great.

    My only issue, is where the formula is close in characters, the system outputs the value for shortest string. As an example:

    if( /E1/i.test(fieldname83) ) return ’30’;
    if( /E10/i.test(fieldname83) ) return ’35’;

    The above is contained in my calculated field, however, if ‘E10′ is entered into fieldname83, it returns the result ’30’ instead of ’35’. I presume, the top formula overrides the second one as it recognises the first two characters and returns the output for ‘E1’.

    Is there a syntax I can add to the formula which addresses this?

    S

    Plugin Author codepeople

    (@codepeople)

    Hello @fabbstar

    You simply should inverse the order of instructions, from the more specific to more general:

    
    (function(){
    if( /E10/i.test(fieldname83) ) return 35;
    if( /E1/i.test(fieldname83) ) return 30;
    })()
    

    Best regards.

    Fabbstar

    (@fabbstar)

    Hey,

    So simple! You genius.

    Very last one…

    I have a field (Single Line Text), I notice there is an option to add the option ‘Validate against a regular expression’. Is there a way I can use this option to ensure there is a space in the text field. For example, I need users to add a space between their post codes e.g. SE1 3DR. I was wondering if this validation option can through an error if the user inputs the post code without the space: e.g. SE13DR.

    Many thanks again,
    Simon

    Plugin Author codepeople

    (@codepeople)

    Hello @fabbstar

    Yes of course, you can define the regular expression you want to validate the field’s values.

    I’m sorry, but I can’t implement the users’ projects as part of support. You can find many tutorials for regular expressions on Internet, for example: Regular-Expressions.info

    Best regards.

    Fabbstar

    (@fabbstar)

    Hey, thanks for that.

    Would this be something you can help me with, for a development fee?

    Many thanks,
    S

    Plugin Author codepeople

    (@codepeople)

    Hi! We’d like to help but we can’t reply about that in this forum. We are not allowed to support any customers in these forums.

    For pro or commercial product support please contact us directly on our site. This includes any pre-sales topics or customization as well.

    Commercial products are not supported in these forums. We will happily answer this and any other questions you can have on our own site.

    Thank you.

    Fabbstar

    (@fabbstar)

    Hey,

    I understand, thanks for that.

    I have found the regular expression online, thanks again for the great plugin and support.

    S

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.