Reg-ex适用于城市和街道 [英] Reg-ex for city and street
问题描述
CITY的RegEx:我们将要求有2个字母字符且没有数字字符。
STREET的正则表达式:有2个连续的字母字符,>
或一个数字和一个alpha,
或一个数字和一个数字,
或一个字母和一个字符串
我尝试了什么:
城市和街道的注册表
有2个连续的字母字符
对于城市,请尝试:
^ [a-zA-Z] {2,}
但......St.Louis? 纽约?您可能希望扩展您的规格。
同样,街道充满了问题:空间非常普遍,第42街非常可能,等等。您可能不希望使用正则表达式中的任何一个 - 有太多的边缘情况会让用户试图输入他们 知道 的数据是正确的但是你的规则不接受。
对于城市,我会使用列表(或自由文本),我允许自由文本的街道。
RegEx for CITY: we will require that there be 2 alpha characters AND no numeric characters.
Regex for STREET :have 2 consecutive alpha characters,
or a number and an alpha,
or a number and a number,
or an alpha and a string
What I have tried:
Reg Ex for City and Street
to have 2 consecutive alpha characters
For city, try:
^[a-zA-Z]{2,}
But ... "St.Louis"? "New York"? You might want to expand your specification.
Similarly, streets are fraught with problems: spaces are very common, "42nd St." is very possible, and so forth. You probably don't want to use a Regex for either of these - there are too many "edge cases" which will frustrate users trying to enter the data they know is correct but your rules don't accept.
For cities, I'd use a list (or free text), for streets I'd allow free text.
这篇关于Reg-ex适用于城市和街道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!