带空格的HTML5表单验证模式字母数字? [英] HTML5 form validation pattern alphanumeric with spaces?

查看:232
本文介绍了带空格的HTML5表单验证模式字母数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < p>我的html5表单中包含以下输入标记:


< label>公司名称*< / label>
< input type =textname =nameclass =fieldrequired pattern =[a-zA-Z0-9] +/>
< / p>

这可以很好地检查公司名称是否由字母数字字符组成。但我当然想要允许公司名称中的空格。我需要知道应该添加到模式中的内容。

解决方案

如何在模式属性中添加空格,如 pattern =[a-zA-Z0-9] +
如果您想支持任何类型的空间,请尝试 pattern =[a-zA-Z0-9 \s] +


I have the following input tag in my html5 form:

<p>
    <label>Company Name*</label>
    <input type="text" name="name" class="field" required pattern="[a-zA-Z0-9]+" />
</p>

This works just fine checking if the company name consists out of alphanumeric characters. But of course I want to allow spaces in the company name. I need to know what I should add to the pattern.

解决方案

How about adding a space in the pattern attribute like pattern="[a-zA-Z0-9 ]+". If you want to support any kind of space try pattern="[a-zA-Z0-9\s]+"

这篇关于带空格的HTML5表单验证模式字母数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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