【发布时间】:2019-05-26 23:58:46
【问题描述】:
我正在用 html 创建一个表单,对于文本输入,我想对其进行正则表达式验证,只允许用户输入:字母、数字和某些字符;
/ - forward slash
- - hyphen
. - period (full stop)
& - ampersand
- spaces
我尝试过这种模式,但无济于事:
[a-zA-Z0-9\/\-\.\&\ ]
我的 HTML 代码:
<input type="text" id="payment_reference" name="payment_reference" maxlength="18" value="' . $payment_reference_default . '" pattern="[a-zA-Z0-9\/\-\.\&\ ]" required>
我知道如何只获取字母字符和数字,但也允许其他字符是我无法管理的。
【问题讨论】:
-
它应该可以工作。你得到什么错误?
标签: regex html validation