use*_*472 8 html jquery html5 jquery-mobile cordova
我在jQuery mobile中实现了iphone和android应用程序.*我使用了**纯jQuery mobile
在文本框中输入电话号码.我使用TYPE ="TEL"'这是用于numaric键盘.
<input type="tel" style=" width:81%;" id="contactNumber" value="" class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset" />
Run Code Online (Sandbox Code Playgroud)
但是用户也可以输入文本框,这是不必要的东西.
How can I prevent user from inserting characters other than numbers?
对于移动设备用户来说,如果唯一的输入可能是数字,则会更舒服,因为他们必须按下每个按钮才能获得数字而不是字母!
我尝试TYPE=”TEL” TYPE=”mumber”
在输入字段中添加,但它无法阻止.
Dal*_*ale 14
$(document).ready(function() {
$('#contactNumber').keyup(function() {
var numbers = $(this).val();
$(this).val(numbers.replace(/\D/, ''));
});
});
Run Code Online (Sandbox Code Playgroud)
这应该替换任何带有空字符*的非数字,因为它们被放入,无需一次搜索多个非数字.
小智 7
以上都没有为我工作,但我找到了一个完全适用于我需要的解决方案(禁止输入字段中的特殊字符).防止和警告用户.
<script>
$("#userlogin").keypress(function(e) {
if (String.fromCharCode(e.which).match(/[^A-Za-z0-9_ ]/)) {
e.preventDefault();
alert("Special characters are not allowed. Use 'A-Z', 'a-z' and '0-9'.");
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16074 次 |
最近记录: |