我想检查输入的城镇和邮政编码是否可行,不需要检查城镇是否存在。
所以我的想法是使用正则表达式解决它,但我找不到正确的解决方案。
格式必须是这样的:
汉堡,22850
或者像这样:
汉堡22850
我试图分别对这些字符和数字进行评估,但是在使用或不使用逗号的情况下
发布于 2018-08-29 10:20:29
这样试试:
[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
https://stackoverflow.com/questions/-100008826
复制相似问题