为什么我在自定义验证后无法输入 % 符号
Why am I unable to enter % sign after my custom validation
我有一个要求,我可以输入不超过100的数字(允许100)。此外,这些数字可以有 +
,-
开头的符号和结尾的%
号。
我想出了以下函数来验证。但是,即使挣扎了很多,我也无法解决为什么我已经输入了 2 位数字时无法输入 %
符号。
例如:键入 10 后,我无法键入 %
(Shift + 5)我的职能:
$scope.checkInputValidation = function(event, value) {
var key = event.keyCode;
var currentcharacter = String.fromCharCode(key);
if (key === 91 || key === 187 || key === 189 || (15 < key && key < 19) || (35 <= key && key <= 40)) {
return;
}
if (isNaN(currentcharacter) && ((currentcharacter !== "%") || (currentcharacter !== "+") || (currentcharacter !== "-") || (currentcharacter !== ""))) {
if ((key !== 46) && (key !== 8)) {
event.preventDefault();
return false;
}
}
var formattedValue;
if (value.indexOf('%') !== -1) {
formattedValue = value.replace('%', "");
} else {
formattedValue = value;
}
if (!isNaN(currentcharacter)) {
if (parseInt(formattedValue + currentcharacter) > 100 || parseInt(formattedValue + currentcharacter) < -100) {
event.preventDefault();
return false;
}
}
}
我想知道原因以及我应该如何进入%
。
currentcharacter
永远不会包含%
字符。您必须结合 event.shiftKey
属性检查 5
(53) 的键代码。
if(key === 53 && event.shiftKey) {
.. % pressed ..
}
相关文章:
- 删除输入中输入的符号
- 为更改的输入返回插入符号位置的逻辑
- 使用 Javascript 在模糊的输入上显示插入符号
- HTML 符号代码在输入字段中无法正常工作
- 为什么我在自定义验证后无法输入 % 符号
- 将符号等♀附加到输入文本字段
- 正则表达式 - 从文本输入中删除美元符号
- 如何在焦点上垂直设置文本区域/输入中间的默认光标插入符号
- 如何通过 JQuery 输入符号
- 将插入符号移到内容中输入的右边可编辑,当插入符号在输入的末尾时
- 如何使用javascript在输入文本中插入符号
- 刷新文本输入以显示插入符号
- 如何在输入标签中创建货币的静态符号
- 试图用%符号追加输入值
- 如何检查数字输入字段中是否输入了字母字符或符号
- 在AngularJS中使用欧元符号格式化输入
- 确定标记化html输入中的插入符号位置
- 无符号右移函数对负输入不起作用
- 赋值时能否防止输入端插入符号跳转到末尾?
- 禁用输入字段中的符号和非字母