In my schema, I want to recognize certain patterns to restrict the type of data that a user can enter. I use regex to restrict what a user can enter, but the regex get flagged when I try to validate the JSON using an online validator like this one.

有没有办法让验证器忽略不同意它的正则表达式特殊字符,但仍然保留正则表达式?

The weird thing is that the validator only trips up on certain instances. For instance, it flags the second and not the first instance of regex despite them being identical here:

            "institutionname": {
                "type": "string",
                "description": "institution name",
                "label": "name",
                "input-type": "text",
                "pattern": "^[A-Za-z0-9\s]+$"
            },
            "bio": {
                "type": "string",
                "label": "bio",
                "input-type": "text",
                "pattern": "^[A-Za-z0-9\s]+$",
                "help-box": "tell us about yourself"
            },

推荐答案

Its just the slashes that are messing up the validation you could encode them using %5C which is the hex encoding of \ or what Mike W says you could double escape like \\ and then you could just decode them when you want to use them

Json相关问答推荐

从Json响应中为需要每个值的Post请求提取多个值

如何形成正确的JQ表达式以从JSON文件中获得准确的输出数据?

对面的行/列进行排序时可能出现错误

在Ansible中从json中提取特定数据

使用 JSON 和相对日期设置日历视图中 SharePoint 列表项的背景 colored颜色 格式

将 json 转换为 jsonb 安全吗?

Spark-SQL中的from_unixtime函数未能给出正确的输出

如何使NiFi将数据库单列中的多个值转化为Solr索引中的数组?

如何按键过滤

打印与 JSON 和 PowerShell 中的模式匹配的子项的父项名称

NiFi 使用嵌套数组将 avro 转换为 JSON 数组格式

如果有 1 个元素,如何防止 ConvertFrom-Json 折叠嵌套数组

如何使用 LINQ 在 C# 中重构对象?

现代浏览器一次可以处理多少个 HTML 元素?

如何使用 Kotlin + Jackson 将 JSON 反序列化为 List

如何将 Swift 对象转换为字典

从 JSON 到 JSONL 的 Python 转换

仅使用字符串和值解析 JSON 对象

Volley JsonObjectRequest Post 参数不再起作用

Java HashMap 与 JSONObject