ExtJs+Json实践例子(2)

// 初始化数据
function initData() {
     if (!searchForm) {
         searchForm = new Ext.FormPanel({
              collapsible : true,
              autoHeight : true,
              frame : true,
              width : 800,
              monitorValid : true,// 把有formBind:true的按钮和验证绑定
              layout : "form",
              labelWidth : 55,
              title : "查询房屋信息",
              renderTo : Ext.getBody(),
              items : [{
                            xtype : "panel",// 默认就是它
                            layout : "column",
                            fieldLabel : "标题",
                            isFormField : true,
                            items : [{
                                          columnWidth : 0.17,
                                          xtype : "textfield",
                                          name : "title",
                                          anchor : "100%"
                                     }, {
                                          columnWidth : 0.4,
                                          layout : "form",
                                          labelWidth : 60,// 注意,这个参数在这里可以调整简单fieldLabel的布局位置
                                          items : [{
                                                        xtype : "datefield",
                                                        fieldLabel : "发布日期",
                                                        name : "booktime",
                                                        anchor : "90%"
                                                   }]
 
                                     }]
                       }, { // 上面是第一行
                            xtype : "panel",
                            layout : "column",
                            fieldLabel : "几室",
                            isFormField : true,
                            items : [{
                                 columnWidth : 0.15,
                                 xtype : "combo",
                                 name : "room",
                                 hiddenName : "room",// 大家要注意的是hiddenName和name属性,name只是下拉列表的名称,作用是可通过,而hiddenName才是提交到后台的input的name。如果没有设置hiddenName,在后台是接收不到真正的值的。
                                 store : new Ext.data.SimpleStore({
                                               fields : ['a', 'b'],
                                               data : [['1', '一'], ['2', '二'],
                                                        ['3', '三']]
                                          }),
                                 valueField : 'a',
                                 displayField : 'b',
                                 mode : 'local',
                                 triggerAction : 'all',
                                 // forceSelection : true,
                                 // selectOnFocus : true,
                                 editable : false,
                                 emptyText : "无限制!",
                                 anchor : "80%"
                            }, {
                                 columnWidth : 0.2,
                                 layout : "form",
                                 labelWidth : 40,// 注意,这个参数在这里可以调整简单fieldLabel的布局位置
                                 items : [{
                                     xtype : "combo",
                                     name : "ting",
                                     hiddenName : "ting",
                                     fieldLabel : "几厅",
                                     store : new Ext.data.SimpleStore({
                                                   fields : ['a', 'b'],
                                                   data : [['1', '一'], ['2', '二'],
                                                             ['3', '三']]
                                               }),
                                     valueField : 'a',
                                     displayField : 'b',
                                     allowBlank : true,
                                     readOnly : true,
                                     mode : 'local',
                                     triggerAction : 'all',
                                     selectOnFocus : true,
                                     emptyText : "无限制!",
                                     anchor : "80%"
                                 }]
                            }, {
                                 columnWidth : 0.15,
                                 layout : "form",
                                 labelWidth : 40,// 注意,这个参数在这里可以调整简单fieldLabel的布局位置
                                 items : [{
                                               fieldLabel : "租金",
                                               xtype : "textfield",
                                               vtype : "double",// 实数格式验证,自己扩展ExtJS
                                               name : "priceStart",
                                               anchor : "95%"
                                          }]
                            }, {
                                 columnWidth : 0.15,
                                 layout : "form",
                                 labelWidth : 10,// 注意,这个参数在这里可以调整简单fieldLabel的布局位置
                                 items : [{
                                               fieldLabel : "至",
                                               labelSeparator : "",
                                               xtype : "textfield",
                                               vtype : "double",// 实数格式验证,自己扩展ExtJS
                                               name : "priceEnd",
                                               anchor : "80%"
                                          }]
                            },
 
                            {
                                 columnWidth : 0.2,
                                 layout : "form",
                                 labelWidth : 40,
                                 items : [{
                                               xtype : "radio",
                                               fieldLabel : "排序",
                                               boxLabel : "升序",
                                               name : "sortCond",
                                               checked : true,
                                               inputValue : "asc",// 这里如果用value,值是on,所以用inputValue(出现这种情况的是radio,checkbox)
                                               anchor : "80%"
                                          }]
                            }, {
                                 columnWidth : 0.15,
                                 layout : "form",
                                 labelWidth : 1,// 让标签宽度为很小的值(奇怪的是为0时反而不行)
                                 items : [{
                                               xtype : "radio",
                                               boxLabel : "降序",
                                               labelSeparator : "",// 去除分隔符“:”
                                               name : "sortCond",
                                               inputValue : "desc",
                                               anchor : "80%"
                                          }]
                            }
 
                            ]
                       }, {
                            xtype : "panel",
                            layout : "column",
                            fieldLabel : "区域",
                            isFormField : true,
                            items : [{
                                 columnWidth : 0.3,
                                 xtype : 'combo',
                                 store : new Ext.data.SimpleStore({
                                               fields : ['id', 'name'],
                                               data : Ext.grid.areaComboBoxItems
                                          }),
                                 valueField : "id",
                                 displayField : "name",
                                 mode : 'local',
                                 // anchor : "60%",
                                 forceSelection : true,// 必须选择一项
                                 emptyText : '请选择区域...',// 默认值
                                 name : "area",
                                 hiddenName : "area",// hiddenName才是提交到后台的input的name
                                 editable : false,// 不允许输入
                                 triggerAction : 'all',// 因为这个下拉是只能选择的,所以一定要设置属性triggerAction为all,不然当你选择了某个选项后,你的下拉将只会出现匹配选项值文本的选择项,其它选择项是不会再显示了,这样你就不能更改其它选项了。
                                 id : 'parent_id',
                                 name : 'parent',
                                 listeners : {
                                     select : function(combo, record, index) {
                                          houseService.getAllStreets(combo.value,
                                                   function(data) {
                                                        if (data != null) {
                                                             var list2 = [];
                                                             for (var i = 0; i < data.length; i++) {
                                                                 list2[i] = [
                                                                           data[i].sid,
                                                                           data[i].sname];
                                                             }
                                                             Ext.grid.streetComboBoxItems = list2;
                                                             Ext.getCmp('child_id')
                                                                      .clearValue();
                                                             Ext.getCmp('child_id').store
                                                                      .loadData(list2);
                                                        }
                                                   });
 
                                     }
                                 }
                            }, {
                                 fieldLabel : '街道',// 默认值
                                 columnWidth : 0.3,
                                 labelWidth : 40,
                                 xtype : 'combo',
                                 store : new Ext.data.SimpleStore({
                                               fields : ['id', 'name'],
                                               data : []
                                          }),
                                 valueField : "id",
                                 displayField : "name",
                                 // 数据是在本地
                                 mode : 'local',
                                 forceSelection : true,// 必须选择一项
                                 emptyText : '请选择街道...',// 默认值
                                 editable : false,// 不允许输入
                                 triggerAction : 'all',// 因为这个下拉是只能选择的,所以一定要设置属性triggerAction为all,不然当你选择了某个选项后,你的下拉将只会出现匹配选项值文本的选择项,其它选择项是不会再显示了,这样你就不能更改其它选项了。
                                 // allowBlank:false,//该选项值不能为空
                                 fieldLabel : '选择',
                                 id : 'child_id',
                                 name : "street",
                                 hiddenName : "street",
                                 anchor : "60%"
                            }
 
                            ]
 
                       }],
              buttons : [{
                            text : "确定",
                            handler : query,
                            formBind : true
                       }, {
                            text : "取消",
                            handler : reset
                        }]
         });
     }
     function query() {
         // alert(DWRUtil.getValue("sortCond"));
         // 这里是关键,重新载入数据源,并把搜索表单值提交
         ds.load({
                       params : {
                            start : 0,
                            limit : ptb.getPageSize(),
                            'cond.title' : Ext.get('title').dom.value,
                            'cond.areaId' : Ext.get('area').dom.value,
                            'cond.streetId' : Ext.get('street').dom.value,
                            'cond.room' : Ext.get('room').dom.value,
                            'cond.ting' : Ext.get('ting').dom.value,
                            'cond.booktime' : Ext.get('booktime').dom.value,
                            'cond.priceStart' : Ext.get('priceStart').dom.value,
                            'cond.priceEnd' : Ext.get('priceEnd').dom.value,
                            'cond.sortCond' : DWRUtil.getValue("sortCond")
                            // 换一种方式获取radio里的值
                            // 取得搜索表单文本域的值,发送到服务端
                       }
                   })
 
     }
     function reset() {
         searchForm.form.reset();
     }
     ds = new Ext.data.Store({
                   // proxy: new Ext.data.MemoryProxy(jsondata),
                   proxy : new Ext.data.HttpProxy({
                                 url : '../house.do'
                            }),
                   reader : new Ext.data.JsonReader({
                                 totalProperty : 'totalProperty',
                                 root : 'root'
                            }, [{
                                          name : 'hid'
                                     }, {
                                          name : 'title'
                                     }, {
                                          name : 'linkman'
                                     }, {
                                          name : 'linktel'
                                     }, {
                                          name : 'hireprice'
                                     }, {
                                          name : 'booktimeInfo'
                                     }, {
                                          name : 'roomTing'
                                     }, {
                                          name : 'areaStreet'
                                     }])
              });
     ds.load({
                   params : {
                       start : 0,
                       limit : limit
                   }
              });
     // 这里很关键,如果不加,翻页后搜索条件就变没了,这里的意思是每次数据载入前先把搜索表单值加上去,
     // 这样就做到了翻页保留搜索条件了.如果struts框架里的form放在session区域,就可以省略。
     // ds.on('beforeload', function() {
     // Ext.apply(this.baseParams, {
     // 'cond.title' : Ext.get('title').dom.value,
     // 'cond.area' : Ext.get('area').dom.value,
     // 'cond.street' : Ext.get('street').dom.value,
     // 'cond.room' : Ext.get('room').dom.value,
     // 'cond.ting' : Ext.get('ting').dom.value,
     // 'cond.booktime' : Ext.get('booktime').dom.value,
     // 'cond.priceStart' : Ext.get('priceStart').dom.value,
     // 'cond.priceEnd' : Ext.get('priceEnd').dom.value,
     // // sortCond : Ext.get('sortCond').dom.value,
     // 'cond.sortCond' : DWRUtil.getValue("sortCond")
     // // 换一种方式获取radio里的值
     // });
     // });
     initGrid();
}
// 初始化显示表格
function initGrid() {
     Ext.QuickTips.init();
     // //
     // win
     // //
     if (!win) {
         win = new Ext.Window({
              el : 'add-window',
                       layout : 'fit', // 布局方式fit,自适应布局
                       width : 350,
                       height : 400,
                       modal : true,
                       plain : true,
                       bodyStyle : 'padding:5px;',
                       maximizable : false,// 禁止最大化
                       closable : true,// 禁止关闭
                       collapsible : true,// 可折叠
                       buttonAlign : 'center',
                       closeAction : 'hide'
 
                   });
     }
     var sm = new Ext.grid.CheckboxSelectionModel();
 
     var cm = new Ext.grid.ColumnModel([sm, {
                   id : 'hid',
                   header : "房屋号",
                   width : 20,
                   sortable : true,
                   dataIndex : 'hid'
              }, {
                   header : "房屋标题",
                   width : 40,
                   sortable : true,
                   dataIndex : 'title'
              }, {
                   header : "联系人",
                   width : 20,
                   sortable : true,
                   dataIndex : 'linkman'
              }, {
                   header : "联系电话",
                   width : 30,
                   sortable : true,
                   dataIndex : 'linktel'
              }, {
                   header : "月租金",
                   width : 30,
                   sortable : true,
                   renderer : function(value) {
                       // Ext.util.Format.usMoney
                       if (value > 1000) {
                            return "<span style='color:red;font-weight:bold;'>"
                                     + value + "</span>元";
                       } else {
                            return "<span style='color:green;font-weight:bold;'>"
                                     + value + "</span>元";
 
                       }
 
                   },
                   dataIndex : 'hireprice'
              }, {
                   header : "发布日期",
                   width : 30,
                   sortable : true,
                   // renderer: Ext.util.Format.dateRenderer('m/d/Y'),
                   dataIndex : 'booktimeInfo'
              }, {
                   header : "房屋格局",
                   width : 40,
                   sortable : true,
                  dataIndex : 'roomTing'
              }, {
                   header : "街道地址",
                   width : 60,
                   sortable : true,
                   dataIndex : 'areaStreet'
              }]);
     //定义一个完整的记录对象
         TopicRecord = Ext.data.Record.create([{
                                                   name : 'hid',
                                                   mapping : 'house.hid'
                                               },{
                                                   name : 'title',
                                                   mapping : 'house.title'
                                               }, {
                                                   name : 'hireprice',
                                                   mapping : 'house.hireprice'
                                               }, {
                                                   name : 'linkman',
                                                   mapping : 'house.linkman'
                                               }, {
                                                   name : 'linktel',
                                                   mapping : 'house.linktel'
                                               },{
                                                   name : 'room',
                                                   mapping : 'house.room'
                                               },{
                                                   name : 'ting',
                                                   mapping : 'house.ting'
                                               },{
                                                   name : 'areaId',
                                                   mapping : 'house.areaId'
                                               },{
                                                   name : 'streetId',
                                                   mapping : 'house.streetId'
                                               },{
                                                   name : 'housething',
                                                   mapping : 'house.housething'
                                               }]); 
     //工具栏对象       
     ptb = new Ext.PagingToolbar({
                   plugins : new Ext.ux.Andrie.pPageSize(),
                   pageSize : limit,
                   store : ds,
                   displayInfo : true,
                   displayMsg : '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
                   emptyMsg : "对不起,查询记录为空!"
              });
     grid = new Ext.grid.GridPanel({
         id : 'button-grid',
         border : false,
         buttonAlign : 'right',
         ds : ds,
         cm : cm,
         sm : sm,
         stripeRows : true,
         loadMask : true,
         viewConfig : {
              forceFit : true
         },
 
         // inline toolbars
         tbar : [{
                       id : 'houseAddBtn',
                       text : '发布',
                       tooltip : '发布一条房屋信息',
                       iconCls : 'add',
                       onClick : function() {
                            // update form to insert form
                            win.title = '添加房屋信息';
                            form = getInsertForm();
                            var items = new Ext.util.MixedCollection();
                            items.add("form", form);
                            win.items = items;
                            win.show();
                            //form.getForm().reset();
                       }
                   }, '-', {
                       id : 'houseEditBtn',
                       text : '编辑',
                       tooltip : '修改一条房屋信息',
                       iconCls : 'option',
                       onClick : function() {
                            if (sm.getCount() == 1) {
                                 // update form to edit form
                                 win.title = '编辑房屋信息';
                                 form = getUpdateForm();
                                 var items = new Ext.util.MixedCollection();
                                 items.add("form", form);
                                 win.items = items;
                                 win.show();
                                 form.getForm().reset();
                                 
                                               var hid = sm.getSelected().data.hid;
                                 houseService.findById(hid, callback);
                                 function callback(data) {
                                                //列表影射,columnModelvar
                                                        var  myNewRecord = new TopicRecord({'house.hid':data.hid, 'house.title': data.title, 'house.hireprice':data.hireprice
                                                        ,'house.linkman':data.linkman,'house.linktel':data.linktel,'house.room':data.room,'house.ting':data.ting,'house.areaId':data.areaId,'house.streetId':data.streetId,'house.housething':data.housething});
                                                        
                                 houseService.getAllStreets(data.areaId, function(
                                          data) {
                                     if (data != null) {
                                          var list2 = [];
                                          for (var i = 0; i < data.length; i++) {
                                               list2[i] = [data[i].sid, data[i].sname];
                                          }
                                          Ext.getCmp('child_id2').clearValue();
                                          Ext.getCmp('child_id2').store
                                                   .loadData(list2);
                                                         // 实际的一条记录
                                     form.getForm().loadRecord(myNewRecord);
                                     }
                                 });
 
                                 }
                            } else {
                                 Ext.MessageBox.alert('提示', '请选择一条记录!');
                            }
                       }
                   }, '-', {
                       id : 'houseDelBtn',
                       text : '删除',
                       tooltip : '删除选择的房屋信息',
                       iconCls : 'remove',
                       onClick : function() {
                            if (sm.hasSelection()) {
                                 Ext.MessageBox.confirm('提示', '你确定要删除这些租房信息么?',
                                          function(button) {
                                               if (button == 'yes') {
                                                   var list = sm.getSelections();
                                                   var rList = [];
                                                   for (var i = 0; i < list.length; i++) {
                                                        rList[i] = list[i].data["hid"];
                                                   }
                                                   houseService.delHouse(rList,
                                                             function(data) {
                                                                 if (data > 0) {
                                                                      Ext.MessageBox
                                                                               .alert(
                                                                                         '提示',
                                                                                         "删除"
                                                                                                  + data
                                                                                                  + '条数据成功!');
                                                                      // 如果把当页数据删除完毕,则跳转到上一页!
                                                                      if (data == ptb.store
                                                                               .getTotalCount()
                                                                               - ptb.cursor) {
                                                                           ptb.cursor = ptb.cursor
                                                                                    - ptb.pageSize;
                                                                      }
                                                                      ds.load({
                                                                           params : {
                                                                               start : ptb.cursor,
                                                                               limit : ptb.pageSize
                                                                           }
                                                                      });
 
                                                                 } else {
                                                                      Ext.MessageBox
                                                                               .alert(
                                                                                         '提示',
                                                                                         "删除数据失败!");
                                                                 }
                                                             });
                                               }
                                          });
                            } else {
                                 Ext.MessageBox.alert('提示', "请至少选择一条记录!");
                            }
                       }
                   }, '-', {
                       id : 'houseRefreshBtn',
                       text : '刷新',
                       tooltip : '刷新房屋信息',
                       iconCls : 'refresh',
                       onClick : function() {
                            ds.load({
                                          params : {
                                               start : ptb.cursor,
                                               limit : ptb.pageSize
                                          }
                                     });
                       }
 
                   }, '-', {
                       id : 'houseCopyBtn',
                       text : '复制',
                       tooltip : '复制添加选择的房屋信息',
                       iconCls : 'copy',
                       onClick : function() {
                            if (sm.getCount() == 1) {
                                 // update form to edit form
                                 form = getInsertForm();
                                 var items = new Ext.util.MixedCollection();
                                 items.add("form", form);
                                 win.items = items;
                                 win.show();
                                 
                                               var hid = sm.getSelected().data.hid;
                                 houseService.findById(hid, callback);
                                 function callback(data) {
                                                //列表影射,columnModelvar
                                                        var  myNewRecord = new TopicRecord({'house.hid':data.hid, 'house.title': data.title, 'house.hireprice':data.hireprice
                                                        ,'house.linkman':data.linkman,'house.linktel':data.linktel,'house.room':data.room,'house.ting':data.ting,'house.areaId':data.areaId,'house.streetId':data.streetId,'house.housething':data.housething});
                                                        
                                 houseService.getAllStreets(data.areaId, function(
                                          data) {
                                     if (data != null) {
                                          var list2 = [];
                                          for (var i = 0; i < data.length; i++) {
                                               list2[i] = [data[i].sid, data[i].sname];
                                          }
                                          Ext.getCmp('child_id1').clearValue();
                                          Ext.getCmp('child_id1').store
                                                   .loadData(list2);
                                                         // 实际的一条记录
                                     form.getForm().loadRecord(myNewRecord);
                                     }
                                 });
 
                                 }
                            } else {
                                 Ext.MessageBox.alert('提示', "请选择一条记录!");
                            }
                       }
 
                   }, '-', {
                       id : 'houseImportBtn',
                       text : '导入',
                       tooltip : '批量导入房屋信息',
                       iconCls : 'import',
                       onClick : function() {
                       }
 
                   }, '-', {
                       id : 'houseExportExcelBtn',
                       text : '导出Excel',
                       tooltip : '导出房屋信息',
                       iconCls : 'export',
                       onClick : function() {
                            window.location = "../houseExport.do?type=excel&start="
                                     + ptb.cursor + "&limit=" + ptb.pageSize;
                       }
                   }, '-', {
                       id : 'houseExportPdfBtn',
                       text : '导出Pdf',
                       tooltip : '导出房屋信息',
                       iconCls : 'export',
                       onClick : function() {
                            window.location = "../houseExport.do?type=pdf&start="
                                     + ptb.cursor + "&limit=" + ptb.pageSize;
                       }
                   }, '-', {
                       id : 'housePrintBtn',
                       text : '打印',
                       tooltip : '打印房屋信息',
                       iconCls : 'print',
                       onClick : function() {
                            //利用IE的简单打印
                            self.print();
                       }
                   }, '-', {
                       id : 'houseDetailBtn',
                       text : '详情',
                       tooltip : '查看所选房屋信息详情',
                       iconCls : 'details',
                       onClick : function() {
                            Ext.MessageBox.alert("详细",'舞动绚丽的ExtJS吧!');
                            Ext.alert(333);
                       }
                   }],
         bbar : ptb,
         width : 800,
         autoHeight : true,
         // height : 250,
         // frame : true,
         title : '房屋信息列表',
         iconCls : 'icon-grid',
         renderTo : document.body
     });
     grid.on('rowcontextmenu', rightClickFn);// 右键菜单代码关键部分
     var rightClick = new Ext.menu.Menu({
                   id : 'rightClickCont',
                   items : [{
                                 id : 'rMenu1',
                                 handler : Ext.getCmp('houseAddBtn').onClick,// 点击后触发的事件
                                 text : '添加信息'
                            }, {
                                 id : 'rMenu2',
                                 handler : Ext.getCmp('houseEditBtn').onClick,
                                 text : '编辑信息'
                            }, {
                                 id : 'rMenu3',
                                 handler : Ext.getCmp('houseDelBtn').onClick,// 点击后触发的事件
                                 text : '删除信息'
                            }, {
                                 id : 'rMenu4',
                                 handler : Ext.getCmp('houseRefreshBtn').onClick,
                                 text : '刷新数据'
                            }, {
                                 id : 'rMenu5',
                                 handler : Ext.getCmp('houseCopyBtn').onClick,// 点击后触发的事件
                                 text : '复制数据'
                            }, {
                                 id : 'rMenu6',
                                 handler : Ext.getCmp('houseImportBtn').onClick,
                                 text : '导入数据'
                            }, {
                                 id : 'rMenu7',
                                 handler : Ext.getCmp('houseExportExcelBtn').onClick,// 点击后触发的事件
                                 text : '导出EXCEL数据'
                            }, {
                                 id : 'rMenu8',
                                 handler : Ext.getCmp('houseExportPdfBtn').onClick,
                                 text : '导出PDF数据'
                            }, {
                                 id : 'rMenu9',
                                 handler : Ext.getCmp('housePrintBtn').onClick,// 点击后触发的事件
                                 text : '打印数据'
                            }, {
                                 id : 'rMenu10',
                                 handler : Ext.getCmp('houseDetailBtn').onClick,
                                 text : '查看详情'
                            }]
              });
 
     function rightClickFn(grid, rowindex, e) {
         e.preventDefault();
         rightClick.showAt(e.getXY());
     }
     // function rMenuFnAdd() {
     // Ext.getCmp('houseAddBtn').onClick;
     // }
     // function rMenuFnEdit() {
     //       
     // }
     // function rMenuFnDel() {
     //       
     // }
     // function rMenuFnRefresh() {
     //       
     // }
     // function rMenuFnCopy() {
     // alert(Ext.getCmp('houseCopyBtn').onClick);
     // return Ext.getCmp('houseCopyBtn').onClick;
     // }
     // function rMenuFnImport() {
     //       
     // }
     // function rMenuFnExportExcel() {
     //       
     // }
     // function rMenuFnExcelPdf() {
     //       
     // }
     // function rMenuFnPrint() {
     //       
     // }
     // function rMenuFnDetail() {
     // return Ext.getCmp('houseDetailBtn').onClick;
     // }
 
}
 
// 扩展extjs的验证!
Ext.apply(Ext.form.VTypes, {
     // 固定电话、传真
     phone : function(v) {
         var r = /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/;
         return r.test(v);
     },
     // 移动电话
     mobile : function(v) {
         var r = /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/;
         return r.test(v);
     },
     // 邮政编码
     zip : function(v) {
         var r = /^[1-9]\d{5}$/;
         return r.test(v);
     },
     // 搜索关键字过滤
     search : function(v) {
         var r = /^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]*$/;
         return r.test(v);
     },
     // 简体中文
     chinese : function(v) {
         var r = /^[\u0391-\uFFE5]+$/;
         return r.test(v);
     },
     // 非中文
     noChinese : function(v) {
         var r = /^^[\u0391-\uFFE5]+$/;
         return r.test(v);
     },
     // 货币
     currency : function(v) {
         var r = /^\d+(\.\d+)?$/;
         return r.test(v);
     },
     // QQ
     qq : function(v) {
         var r = /^[1-9]\d{4,8}$/;
         return r.test(v);
     },
     // 实数
     double : function(v) {
         var r = /^[-\+]?\d+(\.\d+)?$/;
         return r.test(v);
     },
     // 安全密码
     safe : function(v) {
         var r = /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/;
         return !r.test(v);
     },
     phoneText : '请输入正确的电话或传真号码!<br />格式如:0000-XXXXXXXX',
     mobileText : '请输入正确的移动电话号码!<br />格式如:13XXXXXXXXX',
     zipText : '请输入正确的邮政编码!',
     searchText : '请不要输入非法的搜索字符!',
     chineseText : '您只能在这里输入中文字符!',
     noChineseText : '您不能在这里输入中文字符!',
     currencyText : '请输入货币值!<br />格式如:1.00',
     qqText : '请输入合法的QQ号码!',
     doubleText : '请输入实数值,可带+/-号!',
     safeText : '请输入足够安全的字符,包含英文和数字货其他字符!'
});

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值