Badeggsky
 1<script>
 2 function regInput(obj, reg, inputStr)
 3 {
 4  var docSel = document.selection.createRange()
 5  if (docSel.parentElement().tagName != "INPUT"return false
 6  oSel = docSel.duplicate()
 7  oSel.text = ""
 8  var srcRange = obj.createTextRange()
 9  oSel.setEndPoint("StartToStart", srcRange)
10  var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
11  return reg.test(str)
12 }

13</script>
14
15小写英文:<xmp style= "display:inline"> </xmp>
16<input onkeypress = "return regInput(this, /^[a-z]*$/,  String.fromCharCode(event.keyCode))"
17  onpaste  = "return regInput(this, /^[a-z]*$/,  window.clipboardData.getData(\'Text\'))"
18  ondrop  = "return regInput(this, /^[a-z]*$/,  event.dataTransfer.getData(\'Text\'))"
19  style="ime-mode:Disabled"
20><br>
21
22大写英文:<xmp style= "display:inline"> </xmp>
23<input onkeypress = "return regInput(this, /^[A-Z]*$/,  String.fromCharCode(event.keyCode))"
24  onpaste  = "return regInput(this, /^[A-Z]*$/,  window.clipboardData.getData(\'Text\'))"
25  ondrop  = "return regInput(this, /^[A-Z]*$/,  event.dataTransfer.getData(\'Text\'))"
26  style="ime-mode:Disabled">
27<br>
28
29任意数字:<xmp style="display:inline"> </xmp>
30<input onkeypress = "return regInput(this, /^[0-9]*$/,  String.fromCharCode(event.keyCode))"
31  onpaste  = "return regInput(this, /^[0-9]*$/,  window.clipboardData.getData(\'Text\'))"
32  ondrop  = "return regInput(this, /^[0-9]*$/,  event.dataTransfer.getData(\'Text\'))"
33  style="ime-mode:Disabled"
34><br>
35
36限2位小数:<xmp style="display:inline"> </xmp>
37<input onkeypress = "return regInput(this, /^\d*\.?\d{0,2}$/,  String.fromCharCode(event.keyCode))"
38  onpaste  = "return regInput(this, /^\d*\.?\d{0,2}$/,  window.clipboardData.getData(\'Text\'))"
39  ondrop  = "return regInput(this, /^\d*\.?\d{0,2}$/,  event.dataTransfer.getData(\'Text\'))"
40  style="ime-mode:Disabled"
41> 如: 123.12<br>
42
43
44日   期:<xmp style="display:inline"> </xmp>
45<input onkeypress = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,  String.fromCharCode(event.keyCode))"
46  onpaste  = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,  window.clipboardData.getData(\'Text\'))"
47  ondrop  = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,  event.dataTransfer.getData(\'Text\'))"
48  style="ime-mode:Disabled"
49> 如: 2002-9-29<br>
50
51任意中文:<xmp style="display:inline"> </xmp>
52<input onkeypress = "return regInput(this, /^$/,     String.fromCharCode(event.keyCode))"
53  onpaste  = "return regInput(this, /^[\u4E00-\u9FA5]*$/, window.clipboardData.getData(\'Text\'))"
54  ondrop  = "return regInput(this, /^[\u4E00-\u9FA5]*$/, event.dataTransfer.getData(\'Text\'))"
55><br>
56
57部分英文:<xmp style="display:inline"> </xmp>
58<input onkeypress = "return regInput(this, /^[a-e]*$/,  String.fromCharCode(event.keyCode))"
59  onpaste  = "return regInput(this, /^[a-e]*$/,  window.clipboardData.getData(\'Text\'))"
60  ondrop  = "return regInput(this, /^[a-e]*$/,  event.dataTransfer.getData(\'Text\'))"
61  style="ime-mode:Disabled"
62> 范围: a,b,c,d,e<br>
63
64部分中文:<xmp style="display:inline"> </xmp>
65
66<script language=javascript>
67function checkChinese(oldLength, obj)
68{
69 var oTR = window.document.selection.createRange()
70 var reg = /[^一二三四五六七八九十]/g
71 oTR.moveStart("character"-1*(obj.value.length-oldLength))
72 oTR.text = oTR.text.replace(reg, "")
73}

74</script>
75<input onkeypress="return false" onkeydown="setTimeout(\'checkChinese(\'+this.value.length+\',\'+this.uniqueID+\')\', 1)"
76  onpaste  = "return regInput(this, /^[一二三四五六七八九十]*$/,  window.clipboardData.getData(\'Text\'))"
77  ondrop  = "return regInput(this, /^[一二三四五六七八九十]*$/,  event.dataTransfer.getData(\'Text\'))"
78> 范围: 一二三四五六七八九十<br>

分类:

技术点:

相关文章:

  • 2021-11-29
  • 2021-12-27
  • 2021-11-18
  • 2021-08-01
  • 2021-10-19
  • 2021-11-18
  • 2021-11-28
猜你喜欢
  • 2021-11-28
  • 2021-11-18
  • 2021-11-28
  • 2021-12-08
  • 2021-10-19
  • 2020-06-10
  • 2021-12-09
相关资源
相似解决方案