一:最近项目中js数据验证比较多,为了统一风格,移植复用,于是顺手封装了Jquery的插件。

(function($) {
var defaults = {
bugColor: '#FFCCCC', //数据有误的时候文本框颜色
color: 'white', //数据正确时候文本框颜色
type: "alert", //数据错误时候提示方式 alert 弹出框方式 text 赋值span html
msg: "Msg", //数据有误的时候提示内容
ResOjId: 'no'// 当test方式的时候 被赋值的标签 #id
};
function UiProcess(options, rexString, object) {
var options = $.extend(defaults, options);
var values = object.val();
if (rexString.test(values)) {
object.css("backgroundColor", options.color);
return true;
} else {
object.css("backgroundColor", options.bugColor);
if (options.type == "alert") {
alert(options.msg);
}
if (options.type == "text") {
$(options.ResOjId).html(options.msg);
}
return false;
}
}
//验证ip是否符合格式
$.fn.RegIp = function(options) {
var rexString = /^\d{,}\.{}\d{,}\.{}\d{,}/;
return UiProcess(options, rexString, this)
}
//验证座机是否符合格式
$.fn.RegTelPhone = function(options) {
var rexString = /^[-]+[-]?[-]+[-]?[-]$/;
return UiProcess(options, rexString, this) }
//验证手机是否符合格式
$.fn.RegMombilePhone = function(options) {
var rexString = /(^\d{}$)|(^\d{}$)|(^\d{}$)/;
return UiProcess(options, rexString, this) }
//验证中文是否符合格式
$.fn.RegCHZN = function(options) {
var rexString = /[\u4e00-\u9fa5]/;
return UiProcess(options, rexString, this) }
//验证decimal是否符合格式
$.fn.RegDecimal = function(options) {
var rexString = /^[-]+[.]?[-]+$/;
return UiProcess(options, rexString, this) }
//验证decimal保留一位小数是否符合格式
$.fn.RegDecimalSign = function(options) {
var rexString = /^[+-]?[-]+[.]?[-]+$/;
return UiProcess(options, rexString, this) }
//验证整数保留一位小数是否符合格式
$.fn.RegNumber = function(options) {
var rexString = /^[-]+$/;
return UiProcess(options, rexString, this) }
//验证各位整数保留一位小数是否符合格式
$.fn.RegNumberSign = function(options) {
var rexString = /^[+-]?[-]+$/;
return UiProcess(options, rexString, this) }
//验证非空字符
$.fn.IsEmpty = function(options) {
var rexString = /(^.+$)|([\u4e00-\u9fa5])/;
return UiProcess(options, rexString, this) }
})(jQuery);

调用:

 <script type="text/javascript">
function submitOk() {
var interfaceNameInput = $("#<%=interfaceName.ClientID %>");
var userNameInput = $("#<%=userName.ClientID %>");
var passWordInput = $("#<%=passWord.ClientID %>");
var interfaceUrlInput = $("#<%=interfaceUrl.ClientID %>"); ;
if (!interfaceNameInput.IsEmpty({ "msg": "接口名称格式不正确!" })) { return false }
if (!userNameInput.IsEmpty({ "msg": "格式不正确!" })) { return false }
if (!passWordInput.IsEmpty({ "msg": "格式不正确!" })) { return false }
if (!interfaceUrlInput.IsEmpty({ "msg": "格式不正确!" })) { return false }
}
</script>

jquery数据验证插件(自制,简单,练手)的更多相关文章

  1. jquery数据验证插件

    jquery数据验证插件(自制,简单,练手)   一:最近项目中js数据验证比较多,为了统一风格,移植复用,于是顺手封装了Jquery的插件. (function($) { var defaults ...

  2. nice-validator表单验证插件的简单使用

    前言 前端表单校验是过滤无效数据.假数据.有毒数据的第一步,是数据安全的第一道关卡,虽然我们不能100%相信客户端提交的数据(真正的校验还得在服务端进行),但设置前端表单校验也是至关重要的,自己写逻辑 ...

  3. jQuery身份证验证插件

    jQuery身份证验证插件 /*! * jQuery isIDCard Plugin v1.0.0 * http://www.cnblogs.com/cssfirefly/p/5629561.html ...

  4. 基于jquery,bootstrap数据验证插件bootstrapValidator 教程

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...

  5. 基于jquery,bootstrap数据验证插件bootstrapValidator

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...

  6. 【转】基于jquery,bootstrap数据验证插件bootstrapValidator 教程

    bootstrap:能够增加兼容性的强大框架. 因为项目需要数据验证,看bootstrapValidator 还不错,就上手一直,完美兼容,话不多说. 需要引用css: bootstrap.min.c ...

  7. python实现列表页数据的批量抓取练手练手的

    python实现列表页数据的批量抓取,练手的,下回带分页的 #!/usr/bin/env python # coding=utf-8 import requests from bs4 import B ...

  8. 基于jquery、bootstrap的数据验证插件bootstrapValidator使用

    实时验证用户名是否存在,密码不能和用户名相同,两次密码需要相同,提交之后需要验证返回值: <form id="defaultForm" role="form&quo ...

  9. 【转载】jquery validate验证插件,在ajax提交方式下的验证

    正常的表单都是使用submit按钮来提交,jquery  validate插件可以方便的做表单验证. 做一个发送短信的功能,向目标表插入多条记录,界面采用ajax来提交表单,等待效果直接用ext的遮罩 ...

随机推荐

  1. leetcode@ [116/117] Populating Next Right Pointers in Each Node I & II (Tree, BFS)

    https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ Follow up for problem ...

  2. leetcode@ [318] Maximum Product of Word Lengths (Bit Manipulations)

    https://leetcode.com/problems/maximum-product-of-word-lengths/ Given a string array words, find the ...

  3. leetcode@ [36/37] Valid Sudoku / Sudoku Solver

    https://leetcode.com/problems/valid-sudoku/ Determine if a Sudoku is valid, according to: Sudoku Puz ...

  4. $GLOBALS 添加超全局变量

    <?php function test() { $foo = "local variable"; echo '$foo in global scope: ' . $GLOBA ...

  5. 28个你必须知道的HTML5的新特性,技巧以及技术

    原文地址:http://adamlu.com/?p=584#header 总结一下: 1. 新的Doctype 尽管使用<!DOCTYPE html>,即使浏览器不懂这句话也会按照标准模式 ...

  6. .NET设计模式(1):开篇

    转载:http://terrylee.cnblogs.com/archive/2005/12/09/293465.html .NET设计模式开篇 --.NET设计模式系列之一 Terrylee,200 ...

  7. Excel数据导入导出

    1.将sql数据库表中的数据导入到Excel表格里: 方法一.使用StreamWrite对象,这里要注意的是 用“\t”换列,StreamWrite对象的WriteLine方法 一行一行写入. pub ...

  8. 转载jquery $(document).ready() 与window.onload的区别

    jquery $(document).ready() 与window.onload的区别 投稿:mdxy-dxy 字体:[增加 减小] 类型:转载 时间:2009-12-28我要评论 Jquery中$ ...

  9. 【Stage3D学习笔记续】山寨Starling(二):VertexData探幽

    还记得之前的学习笔记中我们的顶点缓冲数组中的顶点数据么,我们使用一个一维数组来记录所有的顶点数据,这是由于顶点缓冲上传数据时是使用的一维数组. 如果对顶点数据进行一层代码的封装,就能更加的方便我们来操 ...

  10. Effective C++ 条款45

    本节条款的题目是运用成员模板接受全部兼容类型 作者阐述自己的观点是通过智能指针的样例. 在学习本节条款之前我们要先明确关于隐式转化的问题 例如以下代码: #include<iostream> ...