使用一些正規表示式和零誤報驗證印度的郵政索引號。正規表示式可在regex.txt
中找到。每個區號都有一個正規表示式(PIN 的第一位數字,從 1 到 8)。可作為 Ruby、Python、Node.js 和瀏覽器的套件提供。
簡單的d{6}
方法將許多無效的 pincode 標記為有效。在 900000 種可能的組合中,只有大約19000
密碼在印度有效。一個簡單的例子是111111
它是一個無效的 pin 碼,但任何簡單的 6 位數字檢查都會將其作為有效的密碼通過。
資料來源是 data.gov.in 上的「全印度 Pincode 目錄」資料集。該資料集的最後更新日期目前為 2019 年 5 月 30 日。
regex.txt
檔案大小為 32KB,因此您可以在任何您想要的地方輕鬆使用它,包括瀏覽器。如果您使用以下任何軟體包,則該軟體包已以壓縮形式交付。您可以直接使用正規表示式,也可以透過一些輔助方法使用。
此專案僅支援各種語言的支援版本。
該軟體包可在packagist
上找到。
要使用 PHP 套件:
use PIN Validator as P ;
// validates a given pincode
// returns boolean
P:: validate ( ' 110011 ' ); // returns true;
// Searches for all valid pincodes in a given string.
// returns array(string)
P:: search ( ' bangalore 560029 ' ); // returns ["560029"]
該軟體包可在npm
上找到。
使用該包:
const P = require ( 'pincode-validator' ) ;
P . validate ( '110011' ) ; // returns true
P . search ( 'my pincode is 560029' ) ; // returns ['560029']
// or directly use the regex in your code
P . exactRegex . match ( '560029' )
"address with pincode (560029)" . matchAll ( P . regex )
請參閱tests/validate.js
以了解更多範例。
將此行新增至應用程式的 Gemfile 中:
gem 'pincode_validator'
然後執行:
$ bundle
或自己安裝:
$ gem install pincode_validator
require 'pincode_validator'
Pin :: valid? ( '560029' ) # returns true
Pin :: valid? ( '111111' ) # returns false
Pin :: search ( 'my pincode is 244713' ) # returns ['244713']
Pin :: search ( 'my pincode is 244713 or 560029' ) # returns ['244713', '560029']
要在瀏覽器中使用它,請下載pincode-regex.js
檔案並將其包含在瀏覽器中。 Pincode
可用作全域變數。
< script src =" ../pincode-regex.js " > </ script >
< script >
Pincode . validate ( "560029" ) ; // returns true
</ script >
您可以使用 githack 直接在程式碼中使用它:https://rawcdn.githack.com/captn3m0/india-pincode-regex/v2.0.0/pincode-regex.js (確保您使用最新版本)。請觀看存儲庫以獲取新版本的通知。
在該專案的程式碼庫、問題追蹤器、聊天室和郵件清單中進行互動的每個人都應遵循行為準則。
CONTRIBUTING.md
以了解一些開發細節和貢獻指南根據 MIT 許可證獲得許可。有關詳細信息,請參閱許可證文件。