87,910
社区成员
发帖
与我相关
我的任务
分享
<!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>Untitled Page</title>
</head>
<body>
<script>
function regInput(obj, reg, inputStr) {
var docSel = document.selection.createRange()
if (docSel.parentElement().tagName != "INPUT") return false
oSel = docSel.duplicate()
oSel.text = ""
var srcRange = obj.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
return reg.test(str)
}
</script>
<input type="text" id="txt" onkeypress = "return regInput(this,/^-0.[1-5]{1}$/,String.fromCharCode(event.keyCode))">
<input type="button" value="test" onclick="test()">
</body>
</html>
<!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>Untitled Page</title>
</head>
<body>
<script>
function regInput(obj, reg, inputStr) {
var docSel = document.selection.createRange()
if (docSel.parentElement().tagName != "INPUT") return false
oSel = docSel.duplicate()
oSel.text = ""
var srcRange = obj.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
return reg.test(str)
}
</script>
<input type="text" id="txt" onkeypress = "return regInput(this, /^-{1}|(-0){1}|(-0.){1}|-0.[1-5]{1}$/, String.fromCharCode(event.keyCode))">
<input type="button" value="test" onclick="test()">
</body>
</html>
<script>
function test(){
var str=document.getElementById("txt").value
var reg=/^-0.[1-5]{1}$/;
alert(reg.test(str))
}
</script>
<input type="text" id="txt"><input type="button" value="test" onclick="test()">
<!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>Untitled Page</title>
</head>
<body>
<script>
function regInput(obj, reg, inputStr) {
var docSel = document.selection.createRange()
if (docSel.parentElement().tagName != "INPUT") return false
oSel = docSel.duplicate()
oSel.text = ""
var srcRange = obj.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
return reg.test(str)
}
</script>
<input type="text" id="txt" onkeypress = "return regInput(this,/^-$|^-0$|^-0.$|^-0.[1-5]{1}$|^0$/,String.fromCharCode(event.keyCode))">
<input type="button" value="test" onclick="test()">
</body>
</html>
<!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>Untitled Page</title>
</head>
<body>
<script>
function regInput(obj, reg, inputStr) {
var docSel = document.selection.createRange();
if (docSel.parentElement().tagName != "INPUT") return false;
oSel = docSel.duplicate();
oSel.text = "";
var srcRange = obj.createTextRange();
oSel.setEndPoint("StartToStart", srcRange);
var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
return reg.test(str);
}
function test(){
var str=document.getElementById("txt").value
var reg=/^-0\.[1-5]{1}|0$/;
alert(reg.test(str))
}
</script>
<input type="text" id="txt" onkeypress="return regInput(this, /^(-|-0|-0\.|-0\.[1-5]{1}|0)$/, String.fromCharCode(event.keyCode))">
<input type="button" value="test" onclick="test()">
</body>
</html>