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.