Validate Canadian Postal Code Regex

后端 未结 7 2277
[愿得一人]
[愿得一人] 2021-02-20 07:12

I have a script written in JavaScript to Validate Canadian Postal Codes using Regex, however it does not seem to be working. Here is the script:

If statement:

         


        
7条回答
  •  一生所求
    2021-02-20 07:37

    Here are the rules http://en.wikipedia.org/wiki/Postal_code#Reserved_characters

    ABCEGHJKLMNPRSTVXY <-- letter used 
    DFIOQU <-- letters not used because it mixes up the reader
    WZ     <-- letters used but not in the first letter
    With that in mind the following in the proper regex
    
    @[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ][\s][0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]
    

提交回复
热议问题