Title: Help with string
Last modified: August 24, 2019

---

# Help with string

 *  Resolved [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/)
 * 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](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11863397)
 * Hello [@fabbstar](https://wordpress.org/support/users/fabbstar/)
 * The preferred solution here would be use regular expressions, as follows:
 *     ```
       if( /E1/i.test(fieldname83) ) return '30.00';
       ```
   
 * Best regards.
 *  Thread Starter [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11882719)
 * 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](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11882767)
 * Hello [@fabbstar](https://wordpress.org/support/users/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.
 *  Thread Starter [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11883178)
 * 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](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11883272)
 * Hello [@fabbstar](https://wordpress.org/support/users/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](https://www.regular-expressions.info/)
 * Best regards.
 *  Thread Starter [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11883412)
 * Hey, thanks for that.
 * Would this be something you can help me with, for a development fee?
 * Many thanks,
    S
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11883589)
 * 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](https://wordpress.org/support/guidelines/#do-not-post-about-commercial-products).
   We will happily answer this and any other questions you can have [on our own site](https://cff.dwbooster.com/contact-us).
 * Thank you.
 *  Thread Starter [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * (@fabbstar)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11883651)
 * 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)

The topic ‘Help with string’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Fabbstar](https://wordpress.org/support/users/fabbstar/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/help-with-string/#post-11883651)
 * Status: resolved