本文整理匯總了TypeScript中validator.matches函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript matches函數的具體用法?TypeScript matches怎麽用?TypeScript matches使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了matches函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
let isURLOptions: ValidatorJS.IsURLOptions;
result = validator.isURL('sample');
result = validator.isURL('sample', isURLOptions);
result = validator.isUUID('sample');
result = validator.isUUID('sample', 5);
result = validator.isUUID('sample', 'all');
result = validator.isUppercase('sample');
result = validator.isVariableWidth('sample');
result = validator.isWhitelisted('sample', 'abc');
result = validator.isWhitelisted('sample', ['a', 'b', 'c']);
result = validator.matches('foobar', 'foo/i');
result = validator.matches('foobar', 'foo', 'i');
}
// **************
// * Sanitizers *
// **************
{
let result: string;
result = validator.blacklist('sample', 'abc');
result = validator.escape('sample');
result = validator.unescape('sample');
示例2: isUserUsernameValid
function isUserUsernameValid (value: string) {
const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`))
}
示例3: validatePassword
private validatePassword(password) {
var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
return validator.matches(password, strongRegex);
}
示例4: isActorPreferredUsernameValid
function isActorPreferredUsernameValid (preferredUsername: string) {
return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp)
}
示例5: function
userSchema.path('is_local').validate(async function(isLocal: boolean) {
// validate presence of password. can't do that in the password validator
// below because it's not run when there's no value (and it can be null,
// if auth strategy is not local). so do it here, invalidate password if
// necessary but return true so provider passes.
if (this.isNew && isLocal) {
if (!this._password) {
this.invalidate('password', 'Password is required.');
}
// idem for username and email
if (!this.username) {
this.invalidate('username', 'Username is required.');
}
if (!this.email) {
this.invalidate('email', 'Email is required.');
}
}
if (isLocal) {
if (!isString(this.username)) {
this.invalidate('username', 'Username must be a string between 3 and 30 characters.');
} else {
if (!isLength(this.username, 3, 30)) {
this.invalidate('username', 'Username must be between 3 and 30 characters.');
}
if (!matches(this.username, /^[a-z0-9]+$/i)) {
this.invalidate('username', 'Username must only contain alpha-numeric characters.');
}
}
}
// TODO put this into separate validation when this is fixed: https://github.com/LearnBoost/mongoose/issues/1919
if (this.preferences && this.preferences.tablefile_name) {
if (!this.preferences.tablefile_name.trim()) {
this.invalidate('preferences.tablefile_name', 'Must not be empty if set.');
}
const rg1 = /^[^\\/:*?"<>|]+$/; // forbidden characters \ / : * ? " < > |
const rg2 = /^\./; // cannot start with dot (.)
const rg3 = /^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i; // forbidden file names
if (!rg1.test(this.preferences.tablefile_name) || rg2.test(this.preferences.tablefile_name) || rg3.test(this.preferences.tablefile_name)) {
this.invalidate('preferences.tablefile_name', 'Must be a valid windows filename, which "' + this.preferences.tablefile_name + '" is not.');
}
}
if (this.preferences && this.preferences.flavor_tags) {
each(flavors.values, (flavorType, flavorId) => { // flavorId: 'orientation', flavorType: { fs: { name: 'Portrait', .. }, ws: { ... } }
if (this.preferences.flavor_tags[flavorId]) {
each(flavorType, (flavorAttrs, flavorValue) => { // flavorValue: 'fs', flavorAttrs: { name: 'Portrait', .. }
if (isUndefined(this.preferences.flavor_tags[flavorId][flavorValue])) {
this.invalidate('preferences.flavor_tags.' + flavorId + '.' + flavorValue, 'Must be provided when providing preferences.flavor_tags.' + flavorId + '.');
}
});
} else {
this.invalidate('preferences.flavor_tags.' + flavorId, 'Must be provided when providing preferences.flavor_tags.');
}
});
}
if (this.preferences && this.preferences.notify_release_moderation_status) {
if (!isBoolean(this.preferences.notify_release_moderation_status)) {
this.invalidate('preferences.notify_release_moderation_status', 'Must be a boolean.');
}
}
if (this.preferences && this.preferences.notify_backglass_moderation_status) {
if (!isBoolean(this.preferences.notify_backglass_moderation_status)) {
this.invalidate('preferences.notify_backglass_moderation_status', 'Must be a boolean.');
}
}
// TODO put this into separate validation when this is fixed: https://github.com/LearnBoost/mongoose/issues/1919
// if (this.channel_config && this.channel_config.subscribed_releases) {
// if (!isArray(this.channel_config.subscribed_releases)) {
// this.invalidate('channel_config.subscribed_releases', 'Must be an array of release IDs.');
// return true;
// }
// const Release = mongoose.model('Release');
// for (let i = 0; i < this.channel_config.subscribed_releases.length; i++) {
// const releaseId = this.channel_config.subscribed_releases[i];
// let rls = await Release.findOne({ id: releaseId }).exec();
// if (!rls) {
// this.invalidate('channel_config.subscribed_releases.' + i, 'Release with ID "' + releaseId + '" does not exist.');
// }
// i++;
// }
// }
return true;
}, 'Error while validating is_local.');