Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 软件时空 > 软件相关 > javascript 对文本框的限制
【标  题】:javascript 对文本框的限制
【关键字】:javascript
【来  源】:http://blog.csdn.net/ziyouhuxill/archive/2006/09/18/1237144.aspx

javascript 对文本框的限制

Your Ad Here <script language=javascript>
 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>
  小写英文:
  <xmp style= "display:inline"> </xmp>
  <input onkeypress = "return regInput(this, /^[a-z]*$/,  String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^[a-z]*$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^[a-z]*$/,  event.dataTransfer.getData('Text'))"  style="ime-mode:Disabled"><br>大写英文:<xmp style= "display:inline"> </xmp>
  <input onkeypress = "return regInput(this, /^[A-Z]*$/,  String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^[A-Z]*$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^[A-Z]*$/,  event.dataTransfer.getData('Text'))"  style="ime-mode:Disabled"><br>任意数字:<xmp style="display:inline"> </xmp>
  <input onkeypress = "return regInput(this, /^[0-9]*$/,  String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^[0-9]*$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^[0-9]*$/,  event.dataTransfer.getData('Text'))"  style="ime-mode:Disabled"><br>限2位小数:<xmp style="display:inline"> </xmp>
  <input onkeypress = "return regInput(this, /^\d*\.?\d{0,2}$/,  String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^\d*\.?\d{0,2}$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^\d*\.?\d{0,2}$/,  event.dataTransfer.getData('Text'))"  style="ime-mode:Disabled"> 如: 123.12<br>日   期:<xmp style="display:inline"> </xmp>
  <input onkeypress = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,  String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,  event.dataTransfer.getData('Text'))"  style="ime-mode:Disabled"> 如: 2002-9-29<br>任意中文:<xmp style="display:inline"> </xmp>
  <input onkeypress = "return regInput(this, /^$/,     String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^[\u4E00-\u9FA5]*$/, window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^[\u4E00-\u9FA5]*$/, event.dataTransfer.getData('Text'))"><br>部分英文:<xmp style="display:inline"> </xmp><input onkeypress = "return regInput(this, /^[a-e]*$/,  String.fromCharCode(event.keyCode))"  onpaste  = "return regInput(this, /^[a-e]*$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^[a-e]*$/,  event.dataTransfer.getData('Text'))"  style="ime-mode:Disabled"> 范围: a,b,c,d,e<br>部分中文:<xmp style="display:inline"> </xmp>
  <script language=javascript>
  function checkChinese(oldLength, obj)
  { var oTR = window.document.selection.createRange()
   var reg = /[^一二三四五六七八九十]/g
   oTR.moveStart("character", -1*(obj.value.length-oldLength))
   oTR.text = oTR.text.replace(reg, "")
   }
   </script>
   <input onkeypress="return false" onkeydown="setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')', 1)"  onpaste  = "return regInput(this, /^[一二三四五六七八九十]*$/,  window.clipboardData.getData('Text'))"  ondrop  = "return regInput(this, /^[一二三四五六七八九十]*$/,  event.dataTransfer.getData('Text'))"> 范围: 一二三四五六七八九十<br>
 
 
(原创)CE MAPI实例讲解 --- Custom Form介绍(九):【上一篇】
服务器管理系统软件:【下一篇】
【相关文章】
  • Javascript 判断日期 ValidDate 函数
  • FireFox 如何用Javascript 修改状态栏status
  • 不知不觉,JavaScript已是如此精彩!
  • JavaScript和DOM的绑定简单例子
  • JavaScript生成xml
  • Javascript控制Web打印(处女贴)
  • 最近想来做个CMS 之类的东西,所以写了我的第一个JavaScript
  • "this" of JavaScript [翻译]
  • 常用的一些javascript小技巧2
  • 常用的一些javascript小技巧 1
  • 【随机文章】
  • 悟空传-第十九章
  • PHP中通过COM访问Access数据库(简易示例)
  • JSF中文输入乱码问题解决方法
  • 解决clent端用applet,server端用ice glacier和storm 实现中间具有防火墙的b/s两端的数据发布订阅的问题
  • 浅析DSLAM的IP上联方式
  • CMM2
  • 八卦一下pplive和迅雷
  • Xslt中递归的实现
  • 在插入数据库时String数据类型无法隐型的转换成money格式,从而无法插入。
  • ADSL Modem PCI
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.