I have an html form and want to create a Javascript code that would check if the Tel. field include only numbers. It is an exercise so I don't want to use jQuery or any other library. I put together this:
HTML
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return numberedFieldsCheck()">
<table>
<tr>
<td>
 <label for="tel">Telephone</label></td>
<td>
 <input type="text" placeholder="00441293603275" name="tel" id="tel" />
 <span id="telFieldIntCheck" style="display:none;color:red">You can only use numbers.</span>
</td>
<td>
 <input type="submit" name="button" id="button" value="Submit" />
 </td>
</tr>
</table></form>
JS
function numberedFieldsCheck(){
    var x=document.getElementById('tel').value;// retrieving value from the form
    console.log(x);
    if(!integerCheck(x)){
        alert('wrong format');
        document.getElementById('telFieldIntCheck').style.display="inline";
        return false;
        }
    }
function integerCheck(userInput) {
var userInputArr=userInput.split('');
for (i=0;i<userInputArr.length;i++){
    if (typeof userInputArr[i]=="number")
            {console.log('format ok')} 
    else {return false};
  }
}
Can you help me with the code? It alerts wrong format regardless of what I put into the input field. Console logs appear for a millisecond and disappear straight away.
onsubmit="numberedFieldsCheck()"to thisonsubmit="return numberedFieldsCheck()"trueexplicitly if everything is alright, right ? I know it returnsundefinedby default.