27 Program to Check Number Length is 10 or not in JavaScript

Program:

<!DOCTYPE html>

<html>



<head>

    <script type="text/javascript">

        function checkNum() {

            var num = document.getElementById('num').value;



            try {

                if (num.length != 10) {

                    throw ("Please enter a 10 digit number");

                } else {

                    document.write(num);

                }

            } catch (e) {

                alert("Error:" + e)

            } finally {

                document.write("<br> Always")

            }

        }

    </script>

</head>



<body>

    <form>

        Enter any number: <input type="text" id="num">

        <input type="button" onclick="checkNum()" value="Check">

    </form>



</body>



</html>


Output:

to check 10 number using regular expression in JavaScript

Previous
Next Post »