Change JavaScript NaN message to someone else

I have an input[type="text"] that throws a NaN error until another field is populated. I know why the message appears, this is not a problem, it is correct. I'm just wondering if I can change "NaN" to something more descriptive for the user.

+4
source share
2 answers
 if(isNaN(input.value)) { input2.value = '';//or a message of your choice } 
+4
source

Check the value with isNaN (value), and if true, then process it however you want.

+3
source

Source: https://habr.com/ru/post/1337926/


All Articles