当前位置: 编程技术>其它
Js 小数验证函数代码(基于正则)
来源: 互联网 发布时间:2014-10-16
本文导语: (1)OnKeyPress 事件验证 用来验证输入操作 代码如下: function OnKeyPressValidate(obj, event, len) { var e = window.event || event; var key = e.keyCode ? e.keyCode : e.which; var selectedText = ""; if (window.getSelection) { var st = obj.selectionStart; var ed = obj.selectionEnd; ...
(1)OnKeyPress 事件验证 用来验证输入操作
function OnKeyPressValidate(obj, event, len) {
var e = window.event || event;
var key = e.keyCode ? e.keyCode : e.which;
var selectedText = "";
if (window.getSelection) {
var st = obj.selectionStart;
var ed = obj.selectionEnd;
selectedText = obj.value.substring(st, ed);
} else if (document.selection) {
selectedText = document.selection.createRange().text;
}
if (selectedText != null && selectedText != "") {
return true;
}
var dot = obj.value.indexOf(".");
len = (typeof (len) == "undefined") ? 2 : len;
if (window.event) {
}
else {
if (key == 8 || key == 9 || key == 46 || (key >= 37 && key
代码如下:
function OnKeyPressValidate(obj, event, len) {
var e = window.event || event;
var key = e.keyCode ? e.keyCode : e.which;
var selectedText = "";
if (window.getSelection) {
var st = obj.selectionStart;
var ed = obj.selectionEnd;
selectedText = obj.value.substring(st, ed);
} else if (document.selection) {
selectedText = document.selection.createRange().text;
}
if (selectedText != null && selectedText != "") {
return true;
}
var dot = obj.value.indexOf(".");
len = (typeof (len) == "undefined") ? 2 : len;
if (window.event) {
}
else {
if (key == 8 || key == 9 || key == 46 || (key >= 37 && key