<input type="text" id="itext" /> <input type="button" value="ok" onclick="pr()"> <script type="text/javascript"> function pr() { var x = document.getElementById('itext').value.length; alert(x > 5 && x < 21); } </script>