I am new at Javascript and I wanted to know if there is a way to check if varibale in java scripts contains anything other than numbers. I have map variable where in I have JSON values as shown below. 'id' is the key of the map.
var map = {};
data = {"id":"01L","rowId":"01L","start":1399919400000,-- - -- -- ------}
map[data.id] = data;
'map[id].start' can have two kind of values as shown. In case 1, there will be only numbers and in case 2, there will be both nums and alphabets.I need to check for this two.
- 1399660200000
- Sat May 10 2014 00:00:00 GMT+0530.
So I need to check if 'map[id].start' contains any alphabets. I have tried the following three ways..But no luck.
method1
if((map[id].start).match(/[^0-9]/)) {
console.log("only numbers");
} else {
console.log("alphabets also");
}
TypeError: match is not a function
method2
if(isNaN(map[id].start)) {
console.log("only numbers");
}else {
console.log("not only numbers");
}
method3
if((map[id].start).indexOf(":")) > 0) {
console.log("not only numbers");
} else {
console.log("only numbers");
}
TypeError: s.indexOf is not a function
Please help me.