{"id":97,"date":"2023-03-17T08:22:36","date_gmt":"2023-03-17T08:22:36","guid":{"rendered":"https:\/\/smartsource.com.sg\/blog\/?p=97"},"modified":"2023-03-17T08:23:08","modified_gmt":"2023-03-17T08:23:08","slug":"validate-singapore-fin-using-python","status":"publish","type":"post","link":"https:\/\/smartsource.com.sg\/blog\/index.php\/2023\/03\/17\/validate-singapore-fin-using-python\/","title":{"rendered":"Validate Singapore FIN using Python"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import re\r\n\r\ndef validate_fin(number):\r\n    # Remove all non-alphanumeric characters from the input\r\n    number = re.sub(r'&#91;^a-zA-Z0-9]', '', number)\r\n    \r\n    # Check if the input is a valid FIN number\r\n    if re.match(r'^&#91;mMfFgG]&#91;0-9]{7}&#91;a-zA-Z]$', number):\r\n        # Check the checksum of the FIN number\r\n        fin_arr = list(number)\r\n        fin_arr&#91;1] = str(int(fin_arr&#91;1]) * 2)\r\n        fin_arr&#91;2] = str(int(fin_arr&#91;2]) * 7)\r\n        fin_arr&#91;3] = str(int(fin_arr&#91;3]) * 6)\r\n        fin_arr&#91;4] = str(int(fin_arr&#91;4]) * 5)\r\n        fin_arr&#91;5] = str(int(fin_arr&#91;5]) * 4)\r\n        fin_arr&#91;6] = str(int(fin_arr&#91;6]) * 3)\r\n        fin_arr&#91;7] = str(int(fin_arr&#91;7]) * 2)\r\n\r\n        weight = sum(&#91;int(i) for i in fin_arr])\r\n        offset = 4 if number&#91;0] in &#91;'T', 'G', 'M'] else 0\r\n        check_code = 'JZIHGFEDCBA'&#91;11 - ((weight + offset) % 11)]\r\n\r\n        return check_code == number&#91;-1].upper()\r\n\r\n    else:\r\n        return False\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[81,64],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-fin","tag-python"],"_links":{"self":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":1,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/97\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}