mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-25 05:25:12 +08:00
# Conflicts: # jsowell-ui/.env.development # jsowell-ui/.env.staging # jsowell-ui/bin/build-sit.bat # jsowell-ui/bin/build.bat # jsowell-ui/src/api/adapayMember/adapayMember.js # jsowell-ui/src/api/pile/merchant.js # jsowell-ui/src/router/index.js # jsowell-ui/src/views/financial/financeDetail.vue # jsowell-ui/src/views/financial/merchant.vue # jsowell-ui/src/views/homeIndex/homeIndex.vue # jsowell-ui/src/views/login.vue # jsowell-ui/src/views/pile/basic/detail.vue # jsowell-ui/src/views/pile/station/components/SiteInfo.vue # jsowell-ui/src/views/pile/station/detail.vue # jsowell-ui/src/views/pile/station/orderReport.vue
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import * as util from '../util';
|
|
|
|
/**
|
|
* 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));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default pattern; |