使用HTML5输入模式匹配字符串,但不是空格 [英] Match a string but not a blank space using HTML5 input pattern

查看:109
本文介绍了使用HTML5输入模式匹配字符串,但不是空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在< input> 中使用HTML5 模式属性来返回特定的匹配字符串:'felfogtam'

I'm using the HTML5 pattern attribute in an <input> to return a match for a specific string: 'felfogtam'

我现在的标记是:

My current markup is:

<input type="text" class="input input-small" pattern="felfogtam">

它确实有效,但如果该字段为空,则输入仍然有效。如何修改正则表达式不允许空白字段?

It does work, but the input is still valid if the field is empty. How can I change the regular expression to not allow a blank field?

推荐答案

添加 必填 属性

<input type="text" class="input input-small" pattern="felfogtam" required>

http:// jsfiddle.net/bJU2D/

这篇关于使用HTML5输入模式匹配字符串,但不是空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆