Goal:
Evaluate a specifik value in my validation code
Problem:
The variable “currentValue” can retrieve a value named “NaN”. And i don’t know what kind of datatype that shall be applied in the my validation process.
Based on my previous test, NaN is neither a string or int or something similiar.
What datatype is NaN?
var ddd = $('#field_timmar').val();
//datac= $('#field_timmar').val();
//len = currentValue.length;
var currentValue = parseInt(ddd);
// Validating message
if(currentValue <= 0)
{
$('#field_timmar_error1').show();
$('#field_timmar_error2').hide();
$('#field_timmar_error3').hide();
nonError = false;
}
else if(currentValue == "NaN" && ddd != "")
{
$('#field_timmar_error2').show();
$('#field_timmar_error1').hide();
$('#field_timmar_error3').hide();
nonError = false;
}
else if(currentValue == "NaN" && ddd == "")
{
$('#field_timmar_error3').show();
$('#field_timmar_error1').hide();
$('#field_timmar_error2').hide();
nonError = false;
}
else
{
$('#field_timmar_error1').hide();
$('#field_timmar_error2').hide();
$('#field_timmar_error3').hide();
}
The data type of NaN is actually Number, but because of its special status, it cannot be directly compared with any other value. There is a function
isNaNthat lets you test whether a number is NaN: