Does Wappler Support Something Like isNaN to Detect if an Input is a Number?

I want to test if the value of an input is a number and then return a 1 or a 0… so something like:

is_valid.setValue(inputA.value.is_nan()?0:1)

How can I do this in Wappler?

I don’t think we have that…but a custom formatter should be pretty easy to make.

If you really want vanilla Wappler, how about attempting to convert the string to a number, and then compare it to the original string?

text1.value && text1.value.toNumber() == text1.value ? 1 : 0

This will work, unless comma’s are used (as in currency). We could replace all commas with empty strings, but that would break some currency formats. Seems like toNumber() should handle this, but currently does not.

I suppose it depends on your exact needs, but a formatter seems the way to go today.

2 Likes

Thanks for your thorough reply Ken! :slightly_smiling_face:

Thank you @mebeingken! Been trying to figure out how to test for numeric since I started using Wappler.

text1.value && text1.value.toNumber() == text1.value ? 1 : 0

Worked like a champ!

2 Likes

Thank you! It saved my life :slight_smile: