我目前有一个正则表达式模式,仅允许“LL”英国邮政编码,并且我将其与带有“pattern”标签的欧芹 JS 一起使用。
data-parsley-pattern="/^[L]{2}[0-9][0-9A-Z]? ?[0-9][A-Z]{2}$/"
我现在需要一个复杂的正则表达式来允许所有“LL”邮政编码和某些“CH”邮政编码。
有人可以告诉我这会是什么样子吗?这对我来说太复杂了。
CH1 6B <---- 1 letter after the B
CH1 6Q <---- 1 letter after the Q
CH4 9A <---- 1 letter after the 0
CH4 9B <---- 1 letter after the 0
CH4 0 <---- 2 letters after the 0
CH5 <---- All variations like the 'LL'regex [0-9][0-9A-Z]? ?[0-9][A-Z]{2}
CH6 <---- All variations like the 'LL' regex [0-9][0-9A-Z]? ?[0-9][A-Z]{2}
CH7 <---- All variations like the 'LL' regex [0-9][0-9A-Z]? ?[0-9][A-Z]{2}
CH8 <---- All variations like the 'LL' regex [0-9][0-9A-Z]? ?[0-9][A-Z]{2}
这个想法是,如果邮政编码以“LL”开头,则继续使用正常的正则表达式,如果邮政编码以 CH 开头,则对“CH”之后的所有内容使用不同的模式
这可能吗?
最佳答案
我刚刚开始使用RegEx
(所以这可能有缺陷),但也许是这样的:
^(LL\d[0-9A-Z]? ?\d[0-9A-Z]{2}|CH1 (6B|6Q)[A-Z]|CH4 (9A|9B)[A-Z]|CH4 0[A-Z]{2}|CH[5-8][0-9A-Z]? ?\d[0-9A-Z]{2})$
关于javascript - 邮政编码的复杂正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60170233/