简体   繁体   English

仅允许特定数字的 HTML 模式输入

[英]HTML Pattern Input to Allow Only Specific Numbers

我想要表单的邮政编码部分,所以只允许 5 个数字,使用 html 模式拒绝任何不以 46,52,53,54,60,61,62 开头的内容

Try the below pattern (starts with one of the specified numbers and then allow 3 digits):尝试以下模式(以指定数字之一开头,然后允许 3 位数字):

^(46|52|53|54|60|61|62)([0-9]{3})$

Here is the running HTML sample.这是正在运行的 HTML 示例。 You may use this pattern in Javascript as well if you want to perform the validation yourself:如果您想自己执行验证,您也可以在 Javascript 中使用此模式:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Prescriptions</title> </head> <body> <form action="#"> Country code: <input type="text" name="country_code" pattern="^(46|52|53|54|60|61|62)([0-9]{3})$" title="Enter five digit number starting with specific numbers"> <input type="submit"> </form> </body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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