Validate Canadian Postal Code Regex

后端 未结 7 2321
[愿得一人]
[愿得一人] 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:35

    A regex approach can validate the format of a Canadian postcode, but it's not sufficient to guarantee that the postcode actually exists.

    For example: A9A 0A0 looks like a valid Canadian postcode, but the forward sortation area A9A doesn't actually exist.

    Are you sure you wouldn't rather do some kind of lookup against an official list of postcodes?

提交回复
热议问题