Change Default Regex Message

Hello again!

Is it possible to alter the error message of a failed regex tied to a text input from the system default "Please match the requested format" to something custom such as "please enter valid number"?

Thanks,

You can create a custom rule for your input. Something like:

{{ textInput2.value.match(/^[0-9]+$/) == null ? "Only numbers pls" : ""}}

Would that work for you?

1 Like

Hi @minijohn

I got some errors when trying to use that. Here is my current regex: "\b{{query6.data['Last 4 SS']}}\b"

That regex queries the DB and if the number does not match it shows that validation error of "Please match the requested format". How would you use the custom rule for that regex and have error message as "please enter valid SSN"?

Thanks again!

So the regex in itself can't query the DB, it will execute on a string (that can come from the DB).

If you want to show query6's results in the textInput1 and have custom validation logic on the input you can:

  • Set the value of the input to {{ query6.data['Last 4 SS'] }}
  • Set the custom rule to {{ textInput1.value.match(/([0-9])\w+/) == null ? "Please enter a valid SSN" : "" }}
  • Set the max length of the input to 4

The match function may not return null, you'll need to have a look there :sweat_smile:

1 Like

Hey @Miotx

This is a very old post, but I had the same question today and thought I'd submit my solution in case anyone else arrives here from a Google search.

Instead of changing the default validation message, I disabled it and used a status component.

The status default value refers to the .invalid property of whatever needs validating. In my case. a text input. I created one status state with Bad String as the label and true as the value. If the input fails validation, Bad String displays. If it doesn't, nothing is displayed and the status component is effectively hidden.

This has the benefit of allowing me to put the new validation messages wherever I want as well as configuring the text and color.

2 Likes

Great work around and thanks for replying!! :sunglasses:

1 Like