如何使用正则表达式模式在URL输入中禁止空格?

3

我正在使用HTML输入类型,你知道标准验证非常宽松。

考虑以下标记:

<form>
    <input type="url" name="link" value="http://jsfiddle .net/" required>
        
    <button type="submit">OK</button>
</form>

我想添加一个自定义的pattern属性来检查用户是否不能提供任何空格
<input type="url" name="link" pattern="what to do here?" required>

你可以复制这个 jsfiddle: http://jsfiddle.net/t6dtbhqo/
1个回答

4

为什么不试试 pattern="[^\s]+"?请看这个链接,我认为它可以工作。

<form>
<input type="url" name="link" value="http://jsfiddle .net/" pattern="[^\s]+"  title="please dont use the white space :)" required>

<button type="submit">OK</button>


1
标题="请不要使用空格 :)" ...... 并查看此链接 - WorkaroundNewbie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接