简体   繁体   中英

regular expression required at least one space in any position

我有一个带有输入字段和模式属性的表单,该表单区分大小写,但是我还需要在任何位置至少有一个空格或更多(必填)

<input type="text" name="name" class="field" required pattern="[\wà-úÀ-Ú]" />

If you want your field to allow only one whitespace then your pattern is .* .*

But if you don't want to allow only whitespace, your pattern is (.+ .*)|(.* .+)

If you don't want the space to appear in the beginning or end, but always preceded and succeeded by a letter, then your pattern is .+ .+

PS: Note the space character in all the patterns

Match all characters followed by least a whitespace character (\\r\\n\\t\\f\\v ) then all characters. This will match when there is a whitespace anywhere in the text.

.*\s.*

The wildcard can be replaced with a character set.

[\wà-úÀ-Ú]*\s[\wà-úÀ-Ú]*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM