Can you pass other params to Custom Validator?

Tags: #<Tag:0x00007fa99aa00f28>

Is it possible to pass custom parameters to a custom validator?

I was looking at documentation for creating a custom validator here:

I’m trying to create a validator for text length, but have it dynamic based on column.
The current method signature looks like:

validator: function(value, callback) {


How could I also pass in the “maxlength” to this function so that I can dynamically validate text lengths on a per column basis?

Hey @mhennessy7

the custom renderer can use a regex. Here’s a snipet from StackOverflow that helps you to create such a regex

1 Like

I am looking for a way to stop/not allow the user to enter more text than a defined max value.
For example, in a phone field, I want to limit amount of text less than 10 characters.

I don’t believe a renderer is a way to stop this, but a validator is? I’m thinking a custom validation function is the best way to enforce this, but I just need a way to pass in a defined max value. Is there no way to do this with a custom validation function?

Maybe something like this

That doesn’t really work. Let me ask you this. On a given column, you can pass the validator parameter.

Is it possible to pass a regex expression directly to this validator parameter? Such as?

<HotColumn width={100} validator={"^[A-Z]{1,10}$"}>

I tried this directly, but got error of "No registered validator found under “/^[A-Z]{1,10}$/” name

Hi @mhennessy7

Can you show your implementation?

Here is a documentation about validator -
As you can see regex is acceptable.

And here is a tutorial relating to data validation -

Thanks for response. I am putting it into a like this:

< – HotColumn key={} title={el.header} data={} validator="/^[0-9]$/" width={el.width} – >

How should I be passing this validator regex when using HotColumn?

You could use validator in this way -

Another way -

Hey @mhennessy7 Does that work for you?

I see the issue, it does work when using the standard cell. However, I’ve needed a custom renderer so that text doesn’t wrap in the cell… I could do the validation in my custom editor/renderer, however how would I change the cell color based on results?

Again, I’m using react HotColumn and custom renderer here and I don’t see a way to change cell color?

Regex should work either way, once you pass the correct data (validator validates what is shown in the getData() method). Validator does not base its rules on rendered data and cellmeta. If you need to base the validation on rendered data you can only process with the server-side validation.

1 Like