防止输入场模式中出现前导空白 [英] Preventing leading white space in input field pattern
问题描述
我正在尝试通过使用模式防止通过空格或制表符在输入中使用前导空格,但是我遇到了此正则表达式^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$
的问题,我认为这是因为我可能不会是否因为引号正确逃脱了?
I'm trying to prevent leading whitespace from being used in an input whether through spaces or tabs by using a pattern, but I'm having issues with this regular expression ^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$
, which I think is because I might not be escaping properly because of the quotation marks?
最终,我想确保输入内容至少包含一个字符,但是在查询开始时,这些字符都不能以空格开头.
Ultimately, I want to make sure the input takes at least one character, but none of those characters be leading white space at the beginning of the query.
_这是一个查询
__这是一个查询
_This is a query
__This is a query
这是一个很好的输入
abc
123
a
<form action="{% url 'master_search' %}" method="GET">
<i class="fa fa-search search-icon-drilldown" aria-hidden="true"></i>
<input type="text" class="nav__search--agency form-control inline" name="q" value="" placeholder="Search by employee name" pattern="^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$" required>
</form>
推荐答案
Hm.如果要允许所有以字母或数字开头的内容,
Hm. If you want to allow everything that starts with a letter or number,
pattern="^[a-zA-Z1-9].*"
应该做这份工作
这篇关于防止输入场模式中出现前导空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!