0

I have few fields that I'm getting from my .txt field and I want to check their type(string, int, date). Also I want to check the length at the same time and I want to allow nulls for some of these fields. I tried to use typeof but that did not work the way it should or I'm missing something in my code. Here is few fields from my .txt file:

FIRST_NAME  LAST_NAME  BIRTH_DATE  GRADE
Mike        Hart       5/24/2002   7
John        Cook       11/05/2003  6
Renn        Voos       4/17/2001   9

Here is my code that I used:

for(var j=0; j < allLines.length; j++){
    var columns = allLines[j].split('\t');
    for(var k=0; k < columns.length; k++){
        console.log(typeof(columns[0]));
    }
}

I noticed the problem when I was checking typeof columns[2] that is BIRTH_DATE(datetime) I was getting 'string' in my console.log. Also when I check for columns[3] that is integer I was getting string in my console.log. I'm wondering if I have to do the trim for these values or something else causing the problem and I'm getting type of string for all fields. What is the best way to check for data types? I was looking in JavaScript and JQuery and type of looks like the most reliable. Thanks in advance.

espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
  • Possible duplicate of [Better way to get type of a Javascript variable?](http://stackoverflow.com/questions/7390426/better-way-to-get-type-of-a-javascript-variable) – Liam Oct 11 '16 at 16:06
  • [Javascript is an untyped language](http://stackoverflow.com/questions/964910/is-javascript-an-untyped-language). Types are rather maluable so this kind of thing is difficult at best. – Liam Oct 11 '16 at 16:07

0 Answers0