mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2025-12-17 16:05:53 +08:00
commit message
This commit is contained in:
42
node_modules/async-validator/lib/rule/pattern.js
generated
vendored
Normal file
42
node_modules/async-validator/lib/rule/pattern.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating a regular expression pattern.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function pattern(rule, value, source, errors, options) {
|
||||
if (rule.pattern) {
|
||||
if (rule.pattern instanceof RegExp) {
|
||||
// if a RegExp instance is passed, reset `lastIndex` in case its `global`
|
||||
// flag is accidentally set to `true`, which in a validation scenario
|
||||
// is not necessary and the result might be misleading
|
||||
rule.pattern.lastIndex = 0;
|
||||
if (!rule.pattern.test(value)) {
|
||||
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
||||
}
|
||||
} else if (typeof rule.pattern === 'string') {
|
||||
var _pattern = new RegExp(rule.pattern);
|
||||
if (!_pattern.test(value)) {
|
||||
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = pattern;
|
||||
module.exports = exports['default'];
|
||||
Reference in New Issue
Block a user