I'd like to know if there is a javascript function that determines whether an input string is a number or a date or neither.
Here's my function and codepen:
function isNumeric(n) {
// http://stackoverflow.com/questions/9716468/is-there-any-function-like-isnumeric-in-javascript-to-validate-numbers
return !isNaN(parseFloat(n)) && isFinite(n);
}
function number_or_string(i) {
// http://stackoverflow.com/questions/7657824/count-the-number-of-integers-in-a-string
if (i.length == 10 && i.replace(/[^0-9]/g, "").length) {
result = 'date'
} else if (isNumeric(i)) {
result = 'number'
} else {
result = 'string'
}
return result
}
Is there a pre-built function that does this (or perhaps a better function, since the above function clearly has limitations)?