Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 确保输入至少包含5位数字_Html_Forms - Fatal编程技术网

Html 确保输入至少包含5位数字

Html 确保输入至少包含5位数字,html,forms,Html,Forms,我构建了一个需要zipcode的小应用程序。我们也可以接受城市和邮政编码。但不管我想要什么,都要有一个zipcode或至少输入5位数字 我该怎么做 这就是我现在的处境: <input type="text" id="address" class="form-control" pattern=".{5,}" title="We Need Your City and Zipcode to proceed." placeholder="ie. New York 25317" required&g

我构建了一个需要zipcode的小应用程序。我们也可以接受城市和邮政编码。但不管我想要什么,都要有一个zipcode或至少输入5位数字

我该怎么做

这就是我现在的处境:

<input type="text" id="address" class="form-control" pattern=".{5,}"
title="We Need Your City and Zipcode to proceed."
placeholder="ie. New York 25317" required>

您可以在表单中输入任意5个字符,但我的应用程序依赖zipcode实现功能。

您的模式应该是: “\b\d{5}\b”

这将确保只允许包含正好5位数字的子字符串的字符串。\b是一个字边界检查器,它将阻止批准6位(或更多)字符串

如果您不担心“超过5位数”,则使用“\d{5}”作为模式