javascript - JS RegExp 表达式并集

标签 javascript

告诉我如何将两个表达式合二为一。 我想在 Angular 4 中的用户验证器中使用

forbiddenValidator (control: FormControl) {
     let login = control.value as string;
     if (login && login.length> 0) {
       if (login.match (/ ^ [0-9] / g) .length> 0) {
         return {
           forbidden: true
         }
       }
       if (login.match (/ [^ A-Z0-9] / gi) .length> 0) {
         return {
           forbidden: true
         }
       }
     }
     return null;
   }

最佳答案

使用|运算符

 regex = /regex1|regex2/gi

关于javascript - JS RegExp 表达式并集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50320597/

相关文章:

javascript - Bootstrap/CSS 输入表单不居中

javascript - 从 DOM 中隐藏元素的属性

javascript - 在 Vuejs 中创建全局变量

javascript - fs.readFile 非常慢,我是否发出了太多请求?

javascript - 如何内联多次调用类方法(链式调用)JavaScript es6

javascript - 使用按钮代替 href 来调用 symfony2 中的操作

javascript - Bot Framework waterfall 中的命名函数?

javascript - 需要 Javascript 延迟

javascript - 在 float 条形图中同时显示悬停和旋转刻度 90 度

javascript - Handsontable - getSelected 不工作