自动排除了 lib,导致js 不全
This commit is contained in:
70
static/src/js/lib/formValidation/validator/regexp.js
Executable file
70
static/src/js/lib/formValidation/validator/regexp.js
Executable file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* regexp validator
|
||||
*
|
||||
* @link http://formvalidation.io/validators/regexp/
|
||||
* @author https://twitter.com/nghuuphuoc
|
||||
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
|
||||
* @license http://formvalidation.io/license/
|
||||
*/
|
||||
|
||||
(function(root, factory) {
|
||||
|
||||
"use strict";
|
||||
|
||||
// AMD module is defined
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define("validator/regexp", ["jquery", "base"], factory);
|
||||
} else {
|
||||
// planted over the root!
|
||||
factory(root.jQuery, root.FormValidation);
|
||||
}
|
||||
|
||||
}(this, function ($, FormValidation) {
|
||||
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
|
||||
'en_US': {
|
||||
regexp: {
|
||||
'default': 'Please enter a value matching the pattern'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FormValidation.Validator.regexp = {
|
||||
html5Attributes: {
|
||||
message: 'message',
|
||||
regexp: 'regexp'
|
||||
},
|
||||
|
||||
enableByHtml5: function($field) {
|
||||
var pattern = $field.attr('pattern');
|
||||
if (pattern) {
|
||||
return {
|
||||
regexp: pattern
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the element value matches given regular expression
|
||||
*
|
||||
* @param {FormValidation.Base} validator The validator plugin instance
|
||||
* @param {jQuery} $field Field element
|
||||
* @param {Object} options Consists of the following key:
|
||||
* - regexp: The regular expression you need to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function(validator, $field, options) {
|
||||
var value = validator.getFieldValue($field, 'regexp');
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
|
||||
return regexp.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return FormValidation.Validator.regexp;
|
||||
}));
|
||||
Reference in New Issue
Block a user