博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

输入框输入限制

Posted on 2013-08-19 17:26  生命如风  阅读(196)  评论(0编辑  收藏  举报
 1  function InputLimits(id) {
 2             $.each(id, function() {
 3                 $("#" + this).bind("keyup", "", function(e) {
 4                     $(this).val($(this).val().replaceNaN());
 5                 }).bind("blur", "", function() {
 6                     $(this).val($(this).val().replaceNaN());
 7                 }).bind("paste", "", function() {
 8                     return false;
 9                 });
10             });
11         }
12 
13         String.prototype.replaceNaN = function() {
14             //return this.replace(/[^0-9]/g, '')   //替换非数字
15             //return this.replace(/[^\w\.\/]/g, '');  //只保留数字 字母
16             return this.replace(/[\u4E00-\u9FA5\uFF00-\uFFFF]/g, '');   //可以输入英文字符,数字,以及符号,就是不能输入中文和全角状态下的符号。
17         }
18 
19         $(document).ready(function() {
20             InputLimits(['<%=txtEquipmentNo.ClientID %>']);
21         });