In Typescript, this shows an error saying isNaN accepts only numeric values
isNaN(\'9BX46B6A\')
and this returns false because parseF
Update 2
This method is no longer available in rxjs v6
I'm solved it by using the isNumeric operator from rxjs library (importing rxjs/util/isNumeric
Update
import { isNumeric } from 'rxjs/util/isNumeric';
. . .
var val = "5700";
if (isNumeric(val)){
alert("it is number !");
}
My simple solution here is:
const isNumeric = (val: string) : boolean => {
return !isNaN(Number(val));
}
// isNumberic("2") => true
// isNumeric("hi") => false;
For full numbers (non-floats) in Angular you can use:
if (Number.isInteger(yourVariable)) {
...
}
function isNumber(value: string | number): boolean
{
return ((value != null) &&
(value !== '') &&
!isNaN(Number(value.toString())));
}