enylin / taiwan-id-validator Goto Github PK
View Code? Open in Web Editor NEW中華民國統一編號、身分證字號驗證規則
License: MIT License
中華民國統一編號、身分證字號驗證規則
License: MIT License
hi 作者你好 我將你的 package 轉成 php 版本
如果有版權問題我將下架我的 php 套件
Starting January 2, 2021 a new ID number format will be introduced for:
the old number format will also remain in place for up to 10 years
Details of the new format and reason for the change at:
https://www.immigration.gov.tw/5382/5385/7445/238440/238442/241508/
https://www.immigration.gov.tw/5385/7445/238440/238442/240309/
「檢查邏輯由可被『10』整除改為可被『5』整除」
營利事業統一編號檢查碼邏輯修正說明
驗證失敗不是例外錯誤 而是預期的結果 (是的 預期他可能會失敗)
使用Throw 可能會導致使用時真的讓使用者感受到無法預期的錯誤發生 而不是驗證失敗的結果
這導致使用方可能被迫再使用的時候得仰賴 catch 來捕捉失敗的驗證
我個人認為 其實只需要建立一個 result 的 interface
例如 像是這樣
export interface ValidateResult {
source: string;
isValid: boolean;
failReason: string;
}
你可以再透過一個快速產生結果的做法來完成他 例如
export namespace ValidateResult {
export Success(source: string): ValidateResult {
return {
source,
isValid: true,
failReason: ''
};
}
export Fail(source: string, failReason: string): ValidateResult {
return {
source,
isValid: false,
failReason,
}
}
}
另外, 通常如果我們在驗證上透過例外的方式來呈現的方法名稱是 ensure
ensure的意思是請保證他符合預期 那麼此時 驗證失敗就是不符合預期的事情
那麼此時再使用 throw Error 來處理驗證失敗的情況
並且再方法回傳時回傳要被驗證的值
讓使用方可以像是回到還沒調用驗證錢的情況下繼續接下來的處理
以上僅建議 如果有不清楚想釐清的部分 也可以討論
我沒有急著想要這些功能 (如果有我就fork or pull request了)
所以只是想提供意見而已
https://unpkg.com/[email protected]/dist/index.min.js
When a corporation uses a lagacy bundle tool, this may resulting in an unwanted build error.
無法判斷的有這些,已經用 taiwanIdValidator.isGuiNumberValid(item.id, true)
還是不行,不知道是不是 edge case:
我放在 gist 因為檔案太大: https://gist.github.com/rockmandash/6acd69c37d9cc0ca92b276b53b25f4be
中華民國已經不復存在了,現在的中國只有中華人民共和國。
你可以說“臺灣省”、“台灣地區”、“台灣特別行政區”。
PRC
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.