How to restrict input box to take only numbers

<input type=”text” name=”card_num” size=”4″ maxlength=”4″ onkeyup=”return isNumberKey(this);”> <script> function isNumberKey(e) { var numberRegex = /^[0-9]+$/; if(!numberRegex.test(e.value)) { e.value = e.value.replace(/\D/g, ”); } } </script>