Html 确保输入至少包含5位数字
我构建了一个需要zipcode的小应用程序。我们也可以接受城市和邮政编码。但不管我想要什么,都要有一个zipcode或至少输入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
<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}”作为模式