首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何实现JS Javascript:Valide德国城镇和邮政编码用逗号分隔?

如何实现JS Javascript:Valide德国城镇和邮政编码用逗号分隔?
EN

Stack Overflow用户
提问于 2018-08-29 00:27:35
回答 1查看 0关注 0票数 0

我想检查输入的城镇和邮政编码是否可行,不需要检查城镇是否存在。

所以我的想法是使用正则表达式解决它,但我找不到正确的解决方案。

格式必须是这样的:

汉堡,22850

或者像这样:

汉堡22850

我试图分别对这些字符和数字进行评估,但是在使用或不使用逗号的情况下

EN

回答 1

Stack Overflow用户

发布于 2018-08-29 10:20:29

这样试试:

代码语言:txt
复制
 [A-Za-z]+               Checks that the first bit is just letters from A to Z (case-insensitive).
          ,?             Allows for 0 or 1 comma(s)
            ␠           Checks whether there is a space
              [0-9]{5}   Checks whether the second half is only made up of 5 digits from 0 to 9
^                     $  Makes sure that the Town Name and Post Code is all that the string contains
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档