<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function txtBlur(ele, filter) {
//debugger;
if (isNaN(ele) && ele.value != "") {
if (isNaN(filter) && filter != "") {
if (!CheckInput(ele.value, filter)) {
alert("check faild");
return false;
}
}
return true;
}
else {
alert("is not null");
return false;
}
}
//通过正则表达式检测
function CheckInput(oInput, filter) {
// var filter = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
if (!filter.test(oInput)) {
return false;
}
return true;
}
//检测是否为 Float类型
function CheckInputIntFloat(oInput) {
if ('' != oInput.value.replace(/\d{1,}\.{0,1}\d{0,2}/, '')) {
oInput.value = oInput.value.match(/\d{1,}\.{0,1}\d{0,2}/) == null ? '' : oInput.value.match(/\d{1,}\.{0,1}\d{0,2}/);
}
}
</script>
</head>
<body>
数字:<input type="text" maxlength="10" οnkeyup="value=value.replace(/[^\d]/g,'')" /><br />
身份证(数字和x):<input type="text" οnkeyup="value=value.replace(/[^\d|x]/g,'')" /><br />
金钱:<input type="text" οnkeyup="value=value.replace(/[^\d|.]/g,'')" οnblur="txtBlur(this,/(^\d{1,}\.{1}\d{1,2}$)|(^\d{1,}$)/)" /><br />
金钱自动更改:<input type="text" οnkeyup="CheckInputIntFloat(this);" /><br />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function txtBlur(ele, filter) {
//debugger;
if (isNaN(ele) && ele.value != "") {
if (isNaN(filter) && filter != "") {
if (!CheckInput(ele.value, filter)) {
alert("check faild");
return false;
}
}
return true;
}
else {
alert("is not null");
return false;
}
}
//通过正则表达式检测
function CheckInput(oInput, filter) {
// var filter = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
if (!filter.test(oInput)) {
return false;
}
return true;
}
//检测是否为 Float类型
function CheckInputIntFloat(oInput) {
if ('' != oInput.value.replace(/\d{1,}\.{0,1}\d{0,2}/, '')) {
oInput.value = oInput.value.match(/\d{1,}\.{0,1}\d{0,2}/) == null ? '' : oInput.value.match(/\d{1,}\.{0,1}\d{0,2}/);
}
}
</script>
</head>
<body>
数字:<input type="text" maxlength="10" οnkeyup="value=value.replace(/[^\d]/g,'')" /><br />
身份证(数字和x):<input type="text" οnkeyup="value=value.replace(/[^\d|x]/g,'')" /><br />
金钱:<input type="text" οnkeyup="value=value.replace(/[^\d|.]/g,'')" οnblur="txtBlur(this,/(^\d{1,}\.{1}\d{1,2}$)|(^\d{1,}$)/)" /><br />
金钱自动更改:<input type="text" οnkeyup="CheckInputIntFloat(this);" /><br />
</body>
</html>