Q:

Counting the length of numbers

I want to validate if the string is  less than 11.
var contact = Number(document.getElementById('field').value);
if(Math.floor(contact) == contact){
    if(contact.toString().length < 11){
    alert("< 11");
    }
    else{
    alert("> 11");
    }
}

First i will check if contact is a valid number, then if it is a number, i will count if it is less than 11. The value of the field must be numbers and it is working when i input 11111111111, but it is not working when it has 0 on it 011111111111. What is wrong in my code? thanks.

A:

replace this
var contact = document.getElementById('#field').value;

with this
var contact = document.getElementById('field').value;

jquery has confused programmers

var contact = document.getElementById('field').value;
if(Math.floor(contact) == contact * 1){
    if(contact.length < 11){
    alert("< 11");
    }
    else{
    alert("> 11");
    }
}

