arthurdejong / python-stdnum

A Python library to provide functions to handle, parse and validate standard numbers.
https://arthurdejong.org/python-stdnum/
GNU Lesser General Public License v2.1
495 stars 205 forks source link

Add swedish postcode validator #271

Closed mchccc closed 2 years ago

mchccc commented 3 years ago

As the title says, this PR adds validation for swedish postal codes

arthurdejong commented 2 years ago

Hi @cicuz

Thanks for your contribution. There are a few issues that should be resolved before merging:

Thanks

mchccc commented 2 years ago

Hello @arthurdejong,

I updated the code as you suggested; I was using the nl module as prototype, and that one is returning a formatted string from the validate() method, even though the situation there is a bit more complicated as the Dutch post codes contain letters as well.

By the way, do you think it's better to return the value as a number or as a string?

Thank you for your input and patience.

mchccc commented 2 years ago

I will be adding tests too, getting accustomed to doctest which I didn't know before

mchccc commented 2 years ago

Ok done, sorry for the spam 😅

Let me know if it's looking alright,

cheers!

arthurdejong commented 2 years ago

Hi @cicuz,

Thanks for the updated PR. I've merged it as 8071444.

I made a few small modifications. In general, postal codes should most likely not be stored as integers because usual mathematic operations on them do not make sense (e.g. adding two postal codes together or multiplying them). I also split the format validation from the length validation and simplified the format() function a bit.

Thanks!

mchccc commented 2 years ago

That's awesome, thank you for the help, guidance, and patience :)

Do you think it'd be possible to package it into a new release?