当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript validator.matches函数代码示例

本文整理汇总了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');
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:31,代码来源:validator-tests.ts

示例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}}$`))
}
开发者ID:jiang263,项目名称:PeerTube,代码行数:5,代码来源:users.ts

示例3: validatePassword

 private validatePassword(password) {
   var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
   return validator.matches(password, strongRegex);
 }
开发者ID:dghijben,项目名称:dashboard,代码行数:4,代码来源:UserController.ts

示例4: isActorPreferredUsernameValid

function isActorPreferredUsernameValid (preferredUsername: string) {
  return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp)
}
开发者ID:jiang263,项目名称:PeerTube,代码行数:3,代码来源:actor.ts

示例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.');
开发者ID:freezy,项目名称:node-vpdb,代码行数:87,代码来源:user.schema.ts


注:本文中的validator.matches函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。