Write an HTML page including any required JavaScript that takes a number from text field in the range of 0 to999 and shows it in words. It should not accept four and above digits, alphabets and special characters.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="number" onchange="f1()"/>
    <div id="ans"></div>
    <script>
        function f1()
        {
            var v=event.target.value;
            if(v>999 || v<0)
            {
                alert("Invalid number(range is 0-999)");
            }
            else
            {
                var ans="";
                //const strRev =  [...v].reverse().join("");
                const strRev=v;
                for(var i=0;i<strRev.length;i++)
                {
                    var d=strRev.charAt(i);
                    //alert(d);
                    switch(d)
                    {
                        case "1":
                            ans+="ONE ";
                            break;

                        case "2":
                            ans+="TWO ";
                            break;

                        case "3":
                            ans+="THREE ";
                            break;

                        case "4":
                            ans="FOUR ";
                            break;

                        case "5":
                            ans="Five ";
                            break;

                        case "6":
                            ans="SIX ";
                            break;

                        case "7":
                            ans="SEVEN ";
                            break;

                        case "8":
                            ans="EIGHT ";
                            break;

                        case "9":
                            ans="NINE ";
                            break;

                        case "0":
                            ans="ZERO ";
                            break;
                    }
                }
                document.getElementById("ans").innerHTML=ans;
            }
        }
    </script>
</body>
</html>