MQTT - How to ignore out of range updates

I have the following thing:

Thing mqtt:topic:mosquitto: AC "AC" (mqtt:broker:mosquitto) [] 
{
  Type number : TargetTemp "Target Temperature"  [ stateTopic="AC/target_temperature/state", commandTopic="AC/target_temperature/command", unit="°C"]
}

Most of the time the updates are between 16 to 34. The problem starts when occasionally the update is NaN.
I would like to create a transformationPattern that ignores such updates and keeps the previous value.

what happened when it received NaN?

Do you need a range filter, which accepts input of, say, 10, or 100, or do you need numeric validation filter, which will accept 10 and 100 but rejects NaN?

I haven’t tested it but I’d imagine NaN wouldn’t be accepted by the mqtt binding anyway?

mqtt has min and max options.

Thanks, I am getting bellow warning::

 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload 'nan' not supported by type 'NumberValue'

The best result will be a numeric validation filter, which will accept numbers between 16 to 32, but rejects NaN or any other values.

You could use REGEX:\d+ (if you don’t receive decimal points) which would silence the NaN warning. REGEX:\d+(\.\d+)? to allow decimal points. Use min/max options to filter out unwanted range if required, but that’s a separate thing.

Thanks, where do I put the REGEX?
I tried to add it to the channel:

Type number : TargetTemp "Target Temperature"  [ stateTopic="AC/target_temperature/state", commandTopic="AC/target_temperature/command", unit="°C", transformationPattern="REGEX:(\d+)"]

But I got below error:

[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'mqtt.things' has errors, therefore ignoring it: [165,264]: mismatched character 'd' expecting set null

Try REGEX:(\\d+) (two backslashes)