Revision: 11240
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 28, 2009 16:27 by juzerali
Initial Code
function checkNum(){ var inputBox = document.getElementById('abc'); if(inputBox.value.length!='0'){ var j=0; var run = false; for(j=0; j<inputBox.value.length; j++){ var char=inputBox.value.charAt(j); if(inputBox.value.charAt(j)>='0' && inputBox.value.charAt(j)<='9'){ run = true; } else{ run = false; alert("Q# can only be a numeric value"); document.getElementById('abc').focus(); document.getElementById('abc').value=""; break; } } if(run){ alert("The field has been successfully validated!"); } } else if(inputBox.value.length == '0'){ alert("Please enter a Q#"); document.getElementById('abc').focus(); } }
Initial URL
Initial Description
This snippet contains a text input field called 'abc' and we calling the checkNum function as the onclick action of a button 'btn'
Initial Title
To check whether a field is numeric by using JavaScript
Initial Tags
javascript
Initial Language
JavaScript