Jquery Easyui verification extension, EasyUI adds verification rules, Easyui verification, Easyui verification, js regular expressions
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sweet Potato YaoJanuary 9, 2017 08:52:19 Monday
http://fanshuyao.iteye.com/
1. Extend the validation rules of easyui
/* easyUI comes with verification */ /* email: Match email regex rule. url: Match URL regex rule. length[0,100]: Between x and x characters allowed. remote['http://.../action.do','paramName']: Send ajax request to do validate value, return 'true' when successfully. */ $.extend($.fn.validatebox.defaults.rules, { phone : {//Mobile phone number verification validator: function(value, param){ return checkPhone(value); }, message: 'Please enter the correct mobile number. ' }, myEmail : {//Email verification, avoid using email and the default conflict validator: function(value, param){ return checkEmail(value); }, message: 'Please enter the correct email address' }, loginName : {//Login name, numbers, English letters or underscores validator: function(value, param){ return checkLoginName(value); }, message: 'Only enter numbers, English letters or underscores' }, telePhone : {//Landline phone, area code and extension number are optional validator: function(value, param){ return checkTelePhone(value); }, message: 'Please enter the correct landline number' }, chinese : {// validator: function(value, param){ return checkChinese(value); }, message: 'Only Chinese characters can be entered' }, number : {//Positive integers, including 0 (00, 01 are not numbers) validator: function(value, param){ return isNumber(value); }, message: 'Only numbers can be entered (01 is not a number)' }, numberText : {//A string of numbers, such as 000222, 22220000, 00000 validator: function(value, param){ return isNumberText(value); }, message: 'Only numeric strings can be entered' }, idCardNo : {//ID card validator: function(value, param){ return isIdCardNo(value); }, message: 'Please enter the correct ID number' }, money : {//amount validator: function(value, param){ return isFloat(value); }, message: 'Please enter the correct number' }, floatNumber : {//Numbers (including positive integers, 0, floating point numbers) validator: function(value, param){ return isFloat(value); }, message: 'Please enter the correct number' }, minLength: { validator: function(value, param){ return value.length >= param[0]; }, message: 'Please enter at least {0} characters. ' }, maxLength: { validator: function(value, param){ return value.length <= param[0]; }, message: 'Cannot enter more than {0} characters. ' } });
2. Use
Add the attribute: validType: 'phone' to the data-option, as shown below:
data-options="required:true,validType:'phone'"
data-options="required:false,validType:'telePhone'"
Three, part of the verification method
/** * remove whitespace from the beginning and end of the string * @param str incoming string value * @author lqy * @since 2015-08-21 */ function trim(str) { if(str == null){ return ""; } return str.replace(/(^\s*)|(\s*$)/g, ""); }; /** * Is it Null * @param object * @returns {Boolean} */ function isNull(object){ if(object == null || typeof object == "undefined"){ return true; } return false; }; /** * Whether it is an empty string, if there are spaces, it is not an empty string * @param str * @returns {Boolean} */ function isEmpty(str){ if(str == null || typeof str == "undefined" || str == ""){ return true; } return false; }; /** * Whether it is an empty string, all spaces are also empty strings * @param str * @returns {Boolean} */ function isBlank(str){ if(str == null || typeof str == "undefined" || str == "" || trim(str) == ""){ return true; } return false; };
/** * Check mobile number * @param z_check_value value to check * @return conforms to return true, otherwise false * @since 2015-08-21 */ function checkPhone(z_check_value) { if(isEmpty(z_check_value) || z_check_value.length != 11){ return false; } var z_reg = / ^ 13 [0-9] {9} | 15 [012356789] [0-9] {8} | 18 [0-9] {9} | (14 [57] [0-9] {8 }) | (17 [015678] [0-9] {8}) $ /; return z_reg.test(z_check_value); };
/** * Check email * @param z_check_value value to check * @return conforms to return true, otherwise false * @since 2015-08-21 */ function checkEmail(z_check_value){ // var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9] ] + [_ | \ _ | \.]?) * [a-zA-Z0-9] + \. [a-zA-Z] {2,3} $ /; var z_reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9] +) * \. [A-Za-z0-9] + $ /; return z_reg.test($.trim(z_check_value)); };
/** * Check the login name (a string consisting of numbers, 26 English letters or underscores) * @param z_check_value value to check * @return conforms to return true, otherwise false * @since 2015-12-29 */ function checkLoginName(z_check_value){ var z_reg = / ^ \ w + $ /; return z_reg.test($.trim(z_check_value)); };
/** * Check phone number * @param z_check_value value to check * @return conforms to return true, otherwise false * @since 2015-08-21 */ function checkTelePhone(z_check_value){ var z_reg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,4}))?$/; return z_reg.test($.trim(z_check_value)); };
/** * Check Chinese only * @param z_check_value value to check * @return conforms to return true, otherwise false * @since 2015-08-21 */ function checkChinese(z_check_value){ var z_reg = /^[\u4E00-\u9FA5\uF900-\uFA2D]+$/; return z_reg.test($.trim(z_check_value)); };
/** * Is it a number * @param z_check_value value to check * @return conforms to return true, otherwise false * @since 2016-10-31 */ function isNumber(z_check_value){ var z_reg = /^(([0-9])|([1-9]([0-9]+)))$/; return z_reg.test($.trim(z_check_value)); };
/** * 是否为数字组成的字符串,01也符合规则 * @param z_check_value 要检查的值 * @return 符合返回true,否false * @since 2017-01-07 */ function isNumberText(z_check_value){ var z_reg = /^([0-9]+)$/; return z_reg.test($.trim(z_check_value)); };
/** * 可以判断是否为数字、金额、浮点数 * @param z_check_value 要检查的值 * @return 符合返回true,否false * @author lqy * @since 2017-01-07 */ function isFloat(z_check_value){ var z_reg = /^((([0-9])|([1-9][0-9]+))(\.([0-9]+))?)$/;//.是特殊字符,需要转义 return z_reg.test($.trim(z_check_value)); };
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2017年1月9日 08:52:19 星期一
http://fanshuyao.iteye.com/