• Resolved shawnm1

    (@shawnm1)


    I’m trying to invalidate a text input field with the following regular expression in the forumla builder:

    var regex = /[a-z]/;
    regex.test(field);

    For this particular use, I need it to reject all letters. I’d use a number field, but I need leading zeros. Any idea why this code doesn’t work?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author EDGARROJAS

    (@edgarrojas)

    mmm i think that would be true only if the letters are lowercase, maybe something like this:

    var regex = /[a-zA-Z]/;
    regex.test(field);

    shawnm1

    (@shawnm1)

    Doesn’t seem to matter either way. It seems like it just ignores the validation check entirely. Upper/lower case doesn’t affect it, numbers don’t affect it. I tried adding the ignore case flag, no difference.
    I know the js is correct, but it’s like smart forms doesn’t see it for some reason. Do I need to enable something somewhere else for it to use formulas?

    shawnm1

    (@shawnm1)

    Do I need to put this in the JavaScript tab instead of the conditional logic formula builder?

    I think I have a lead on what’s going on.
    Using String(field).length on a field that is a text input operates exactly the same as using String(field).length on a number. I.e., in either case, if the input begins with a 0, for example, 01234, the conversion drops the 0.
    What are text fields “stored” as? It can’t be a string. Converting a string to a string shouldn’t drop characters. Converting a number to a string would. Are these stored as arrays or objects or something? I can’t think of any reason a string being converted to a string should drop characters.
    Further, taking out String(field).length, in favor of just (field).length just ignores it. Field.length has a syntax error.

    I think the regex problem is related to this data type issue I’m having.

    Plugin Author EDGARROJAS

    (@edgarrojas)

    Got it, the formulas actually doesn’t work with scalar values (like numbers or strings) all of them are objects. By default all the fields are converted to number because by far numeric operations are the most frequent use of the formula builder. If you want to use the ‘string’ value directly please try something like this: $$field_rnField1$$.label

    Regards!

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