Class OpenVerify
java.lang.Object
cloud.opencode.base.string.regex.OpenVerify
Verification Utility - Provides checksum-based verification algorithms
校验工具类 - 提供基于校验位的验证算法
Unlike RegexPattern which only checks format via regex,
this class performs full algorithmic verification including checksum validation.
不同于 RegexPattern 仅通过正则检查格式,
此类执行完整的算法校验,包括校验位验证。
Features | 主要功能:
- Luhn algorithm (bank cards, IMEI) - Luhn 算法(银行卡、IMEI)
- China 18-digit ID card checksum - 中国18位身份证校验位
- China 15-digit ID card validation - 中国15位身份证校验
- USCI (Unified Social Credit Identifier) checksum - 统一社会信用代码校验位
Usage Examples | 使用示例:
boolean validCard = OpenVerify.isLuhn("4111111111111111");
boolean validId = OpenVerify.isValidIdCard18("110101199003077735");
boolean validUsci = OpenVerify.isValidUSCI("91110000MA001ABCX5");
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Null-safe: Yes (returns false for null) - 空值安全: 是(null返回false)
- Since:
- JDK 25, opencode-base-string V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisCreditCard(String cardNumber) Validates a credit/debit card number using the Luhn algorithm.static booleanisIdCard15(String idCard) Validates a China 15-digit ID card number.static booleanisIdCard18(String idCard) Validates a China 18-digit ID card number with checksum verification.static booleanValidates a number using the Luhn algorithm (MOD 10).static booleanValidates a Unified Social Credit Identifier (USCI / 统一社会信用代码).
-
Method Details
-
isLuhn
Validates a number using the Luhn algorithm (MOD 10). 使用 Luhn 算法(MOD 10)校验数字。Applicable to credit/debit card numbers, IMEI numbers, etc.
适用于银行卡号、IMEI 号等。
- Parameters:
digits- the digit string to validate- Returns:
- true if valid according to Luhn algorithm
-
isCreditCard
Validates a credit/debit card number using the Luhn algorithm. 使用 Luhn 算法校验银行卡号。Strips non-digit characters before validation. Valid card numbers are 13-19 digits.
校验前去除非数字字符。有效卡号为 13-19 位。
- Parameters:
cardNumber- the card number (may contain spaces/dashes)- Returns:
- true if valid card number
-
isIdCard18
Validates a China 18-digit ID card number with checksum verification. 校验中国18位身份证号(含校验位验证)。Performs weighted sum modulo 11 checksum calculation.
执行加权求和模 11 校验位计算。
- Parameters:
idCard- the 18-digit ID card number- Returns:
- true if valid (format + checksum)
-
isIdCard15
Validates a China 15-digit ID card number. 校验中国15位身份证号。- Parameters:
idCard- the 15-digit ID card number- Returns:
- true if valid (all digits, correct length)
-
isUSCI
Validates a Unified Social Credit Identifier (USCI / 统一社会信用代码). 校验统一社会信用代码。Performs weighted sum modulo 31 checksum calculation using the character set: 0-9, A-H, J-N, P, Q, R, T, U, W, X, Y.
使用字符集 0-9, A-H, J-N, P, Q, R, T, U, W, X, Y 执行加权求和模 31 校验位计算。
- Parameters:
usci- the 18-character USCI code- Returns:
- true if valid (format + checksum)
-