regex - Regex don't work in reactive form control
问题描述
I have the following regex for URL that require to start from http or https
(http:|https:)+[^\s]+[\w]
that work very good for what I want (https://regexr.com/598hs)
But when I try to run it in angular validation, it doesn't work.
this.form = fb.group({
numberCode: ['', Validators.pattern(`(http:|https:)+[^s]+[w]/g`)]
})
https://stackblitz.com/edit/angular-reactive-forms-validation-lulnas
Why so ?
解决方案
您也可以尝试通过以下方式进行匹配:Validators.pattern(/^(http:|https:)+[^\s]+.+.+.+$/)
推荐阅读
- python - 如何使用 Python 3.8.5 安装 vtkplotter?
- java - java-处理浮点舍入错误,如何保持弧度合理
- python - 重新缩放拼接图像中的边界框注释
- javascript - 如何创建过滤器以动态呈现获取的项目
- entity-framework - 当 DTO 中缺少某些属性时,如何将 DTO 对象映射到实体?
- azure - 如何在存储资源管理器中使用 SAS URI 将文件夹上传到 Blob 存储
- swift - 隐藏导航栏 SwiftUI for MacOS 11.1
- flutter - 您是否应该在按钮中等待 Navigator 调用
- php - 从不同的复选框创建数组然后序列化的最佳方法是什么?
- vhdl - 如何将多个 VHDL 代码组合成一个系统