Hi everyone. This is my first time posting for help, so I'm sorry if I have not included enough information.

I'm having some trouble with a form I am working on.

The form is simple, it just has some text boxes and selection menus asking for information like name and phone number. There are two buttons. One displays the entered information at the bottom of the screen, and the other checks to see if the phone number is 10 digits long, and does not include any non-numeric characters. This is the button I'm having an issue with.

Code:
function checkNumber()
{
//Initialize variables
var userPhone = "";
var msg = "";
var numberLength = 0;
var checkDigits = false;
var checkLength = false;

userPhone = document.getElementById('phoneNumber').value; //Get contents of input typed into phone number box

	//Check to ensure length is exactly 10 characters
	if (userPhone.length < 10 || userPhone.length > 10) 
	{
		msg = "Sorry, ten digits were not entered. Try again.";
		document.getElementById('phoneDisplay').innerHTML = msg;
	}
	else {
		checkLength = true;
	}

	//Check for non-numeric characters
	numberLength = userPhone.length;
	for (i = 0; i < numberLength; i++) 
		{
			if ((userPhone.charCodeAt(i) < 48) || (userPhone.charCodeAt(i) > 57)) //Unicode for 0-9 is decimal 48-57
			{
				msg = "Sorry, one or more characters entered was not a number.";
				document.getElementById('phoneDisplay').innerHTML = msg;
			}
		else 
			{
				checkDigits = true;
			}
		}
		
	if ((checkLength === true) && (checkDigits === true)) 
		{ 
			msg = document.getElementById('phoneNumber').value;
			document.getElementById('phoneDisplay').innerHTML = msg; //If both checks are met, the number is displayed
		}

}
How it should work
If the number is not 10 digits long, or includes non-numeric values, an error message is displayed in <span id=phoneDisplay</span>. If it is entered correctly, the 10 digit phone number will display here. I am using the ASCII code equivalents of 0-9 to specify whether or not a character is a number or not.

How it is actually working
Length seems OK. If it's not 10 digits, no matter if its letters or numbers entered, it does not work. However, there are problems with the number check. If I enter all letters or letters at the beginning, the error is displayed. If I enter letters in the middle of the string, there is no error and the number (like 610ABC7891) is displayed. This shouldn't be happening.

Is anyone able to point me in the right direction? I've been at this for a few hours, and have not been able to make it 100% functional.