无法使正则表达式处理 HTML 模式属性

Cannot make regex working on HTML pattern attribute

我的 regexregex101 上运行良好,我的 regex 是

[1-4]|(0)

但是当我在 HTML 输入元素的属性上尝试它时,它没有按预期工作。我的 HTML 如下所示

<form action="/">
     <input type="text" id="usernum" name="usernum" pattern="[1-4]|(0)" title="1-4 and must include at leat one 0">
     <input type="submit">
</form>

我希望用户必须输入一个 0 以及范围数字。

pattern 属性必须匹配整个输入。

([1-4]+0[0-4]*|[0-4]*0[1-4]+)+

第一个选项在 0 之前至少需要一个数字 1-4,第二个选项在 0 之后至少需要一个数字 1-4。然后用 + 重复它以允许多个 0.

DEMO