如何在数字输入栏中停止接受字母e。 [英] How to stop the letter e being accepted in number input field.
问题描述
我有许多纯粹整数的输入,即0到54.
因此我的输入代码是
I have a number of inputs which are purely integers namely 0 to 54.
My code for input is thus
<td> <input id="P1HC" name="P1HC" type="number" min="0" max="54" size= "1" pattern="^[1-9]$" value="<?php echo $_SESSION["HC1"]; ?>"> </td>
但是,我仍然可以在输入中键入e。除了0到9或e之外,它不会接受任何其他字母或字符。
另外我可以输入大于54的数字为什么?
任何想法?
计划在PHP服务器端进行验证,但想先在用户端进行检查。
什么我试过了:
还尝试添加
However, I can still type 'e' into the input. It will not accept any other letter or characters other than 0 to 9 or e.
Also I can type in numbers greater than 54 why?
Any ideas?
Plan to validate in PHP server side but wanted to check at the user side first.
What I have tried:
Also tried adding
onchange = "check(this)"
,javascript为
with javascript of
function check(that) {
var StringInput = that.value;
if (!/^[1-9]*$/g.test(StringInput)) {
alert("You have entered invalid characters");
that.value = "";
that.focus();
return false;
}
}
仍然无效。
Still did not work.
推荐答案
value = <?php echo
" value="<?php echo
_SESSION [HC1]; ?>>< / td>
_SESSION["HC1"]; ?>"> </td>
但是,我仍然可以在输入中键入e。它不会接受0到9或e以外的任何其他字母或字符。
另外我可以输入大于54的数字为什么?
任何想法?
计划在PHP服务器端进行验证,但想先在用户端进行检查。
我尝试了什么:
还尝试添加
However, I can still type 'e' into the input. It will not accept any other letter or characters other than 0 to 9 or e.
Also I can type in numbers greater than 54 why?
Any ideas?
Plan to validate in PHP server side but wanted to check at the user side first.
What I have tried:
Also tried adding
onchange = "check(this)"
,javascript为
with javascript of
function check(that) {
var StringInput = that.value;
if (!/^[1-9]*
/g.test(StringInput)){
alert(您输入了无效字符);
that.value =;
that.focus();
返回false;
}
}
/g.test(StringInput)) { alert("You have entered invalid characters"); that.value = ""; that.focus(); return false; } }
仍然无效。
Still did not work.
这篇关于如何在数字输入栏中停止接受字母e。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!