gpt4 book ai didi

javascript - 邮政编码的正则表达式是什么,即 96754-2222

转载 作者:行者123 更新时间:2023-11-28 12:22:19 25 4
gpt4 key购买 nike

 <input class="input-width" placeholder="XXXXX" maxlength="10"
type="text" name="zip" ng-model="shipping.zip" required ng-pattern="/^[0-9]+$/" />

这仅输入数字。我如何输入 5 个数字,然后输入“-”,然后输入 4 个数字。我是正则表达式的新手。谁能帮我创建这个。

最佳答案

这符合您的要求:

^[0-9]{5}(?:-[0-9]{4})?$

即:

 characters 0-9
| 5 of them
| |
v v
^[0-9]{5}(?:-[0-9]{4})?$
^^^ ^
| |
| group is optional
|
group (no-capture)

查看注释。在字符串的开头和结尾处还有一个文字 - 破折号以及 ^$ anchor 。

5 位数字,后跟可选的 - 和 4 位数字。

关于javascript - 邮政编码的正则表达式是什么,即 96754-2222,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35277769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com