Angular验证:输入应该包含拉丁字符或格鲁吉亚字符,但两者不能同时包含。
创始人
2024-10-30 11:30:13
0

在 Angular 中进行此类验证可以使用自定义验证器。以下是一个示例代码,用于验证输入框中的内容是否同时包含拉丁字符和格鲁吉亚字符:

import { FormControl } from '@angular/forms';

export function noMixedChars(control: FormControl) {
  const latinPattern = /^[\u0000-\u007F]+$/;
  const georgianPattern = /^[\u10A0-\u10FF]+$/;

  const value = control.value;

  if (!value) {
    return null;
  }

  if (latinPattern.test(value) && georgianPattern.test(value)) {
    return { mixedChars: true };
  }

  return null;
}

在模板中使用时,可以这样写:


Input should either contain Latin or Georgian characters, but not both of them together

这样就会在输入框中出现错误信息,当同时输入拉丁字符和格鲁吉亚字符时,会将错误信息显示出来。

相关内容

热门资讯

透视工具!wepoker手机版... 透视工具!wepoker手机版辅助(透视)wepoker黑侠辅助器(确实真的有挂)-哔哩哔哩1、该软...
透视神器!花花生活圈怎么开挂(... 透视神器!花花生活圈怎么开挂(辅助)掌中乐辅助(一直有挂)-哔哩哔哩1、用户打开应用后不用登录就可以...
透视软件!wepoker透视有... 透视软件!wepoker透视有吗(透视)poker world辅助(果然一直都是有挂)-哔哩哔哩一、...
透视插件!wepoker透视辅... 透视插件!wepoker透视辅助下载(透视)wepoker辅助分析器(都是是有辅助器)-哔哩哔哩we...
透视app!wepoker黑侠... 透视app!wepoker黑侠辅助器正版下载(透视)wepokerplus透视脚本免费(都是一直总是...
透视插件!pokemmo手机脚... 透视插件!pokemmo手机脚本辅助器(透视)哈糖大菠萝破解器(竟然有脚本)-哔哩哔哩1、全新机制【...
透视app!aapoker安装... 透视app!aapoker安装包怎么使用(透视)aapoker俱乐部靠谱吗(原来有透视)-哔哩哔哩1...
透视app!佛手在线大菠萝辅助... 透视app!佛手在线大菠萝辅助(透视)竞技联盟辅助(本来真的有辅助器)-哔哩哔哩1、下载好佛手在线大...
透视攻略!博雅红河西元红河修改... 透视攻略!博雅红河西元红河修改器(辅助)同乡有辅助(其实一直都是有辅助器)-哔哩哔哩博雅红河西元红河...
透视脚本!wepoker亲友圈... 透视脚本!wepoker亲友圈有用吗(透视)wepoker手机插件(都是有辅助器)-哔哩哔哩1、实时...