regex - 如何验证 Yup 中的非必需文件
问题描述
如何验证不应包含以下特殊字符 #<`>
和点(。)之前的空格的非必需文件我有正则表达式\`|\#|\&|\<|\ \.|\>
来验证上述条件,但不知道如何使用 yup.matches() 来处理这个正则表达式。提前致谢
Regex: \`|\#|\&|\<|\ \.|\>
我的验证模式是:
const validationSchema = function (values) {
var regx = new RegExp(/\`|\#|\&|\<|\ \.|\>/gms);
return Yup.object().shape({
about: Yup.string()
.matches(expression, 'about should not contain ` # < > \n')
})
}
解决方案
假设您的正则表达式有效,您可以使用string.matches函数。这是文档中的示例:
var v = string().matches(/(hi|bye)/);
v.isValid('hi')
.should.eventually()
.equal(true);
v.isValid('nope')
.should.eventually()
.equal(false);
推荐阅读
- jquery - 如何在方法外访问jquery更改事件值?
- ffmpeg - 组合两个 ffmpeg 命令(片段和静态照片)
- azure - 如何在 Azure 应用服务中指定分层应用设置?
- sockets - 重新连接以太网时,UDP Socket 会写入过期的数据包。以太网断开连接时,如何从套接字刷新写缓冲区?
- python-3.x - 绘制一个沿着色散波移动的点?
- sql - SQL 视图:优化实时数据
- r - 将列名从不同的数据帧传递给ggplot
- coreclr - 从 git 存储库构建 .NET Core 3.1.1
- java - AsyncTask 和 RecyclerView 不显示互联网上从 JSON 获取的内容
- nginx - 具有两个独立服务器的安全 WebSocket 的 Nginx 反向代理