• Resolved cath_allen14

    (@cath_allen14)


    Hi,

    I have a text field where customers can input their postcode. I want to match the first two characters of the inputted postcode against a value.

    E.g. a customer could enter MK45 which would return a value of 300 but I want to just match just the first two cahracters, in this case MK, but allow the customer to enter the full postcode i.e MK45 5HH.

    (function(){
    if((fieldname373 == ‘MK’) || (fieldname373 == ‘SG’)) return 300;
    if((fieldname374 == ‘HA’) || (fieldname374 == ‘W1’)) return 500;
    })()

    Also, is there a way for the string entered in the text field to be converted to uppercase so that even if the customer enters their postcode in lowercase it is still checked?

    Thanks in advance!

    Catherine

    • This topic was modified 5 years, 4 months ago by cath_allen14.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @cath_allen14

    The preferred solution in your case would be using regular expressions, instead of pre-process the values entered by the user.

    For example, your equation would be:

    
    (function(){
        if(/^\s*(mk|sg)/i.test(fieldname373)) return 300;
        if(/^\s*(ha|w1)/i.test(fieldname374)) return 500;
    })()
    

    and that’s all.
    Best regards.

    Thread Starter cath_allen14

    (@cath_allen14)

    Ahhh brilliant – thanks for such a quick reply!

    Catherine

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Text Field Match Substring and convert to uppercase’ is closed to new replies.