gpt4 book ai didi

dart - Flutter/Dart 中的驾照验证

转载 作者:IT王子 更新时间:2023-10-29 07:20:24 25 4
gpt4 key购买 nike

有谁知道可以在 flutter 项目中使用的 API 或包,可以让我检查驾照号码是否有效?如果有影响的话,我正在使用美国驾照。

最佳答案

似乎还没有插件,但由于它可以在大多数语言中以完全相同的方式完成,所以它已经完成了。看看:https://stackoverflow.com/a/29835561/6696558 .

在 Dart 中它会是这样的:

class DriverLicenseValidator {
// From http://www.uiia.org/documents/license_guidelines_08.pdf
static final oneToSevenNumeric = RegExp(r'^[0-9]{1,7}$');
static final oneAlpha = RegExp(r'(.*[A-Za-z]){1}');
static final oneAlphaPlusSeven = RegExp(r'^.[0-9]{7}$');
static final twoAlpha = RegExp(r'(.*[A-Za-z]){2}');
static final alphaPlusSixNumeric = RegExp(r'(.*[0-9]){6}$');
static final threeToFiveNumeric = RegExp(r'(.*[0-9]){3,5}$');
static final fiveToNineNumeric = RegExp(r'(.*[0-9]){5,9}');
static final sixNumeric = RegExp(r'^[0-9]{6}$');
static final sevenNumeric = RegExp(r'^[0-9]{7}$');
static final sevenToNineNumeric = RegExp(r'^[0-9]{7,9}$');
static final eightAreNumbers = RegExp(r'(.*[0-9]){8}');
static final nineNumeric = RegExp(r'^[0-9]{9}$');
static final nineAlphaChars = RegExp(r'^[A-Za-z0-9]{9}$');
static final tenNumeric = RegExp(r'^[0-9]{10}$');
static final elevenNumeric = RegExp(r'^.[0-9]{11}$');
static final twelveNumeric = RegExp(r'^.[0-9]{12}$');
static final hPlusEight = RegExp(r'([H][0-9]{8})$');
static final sevenPlusX = RegExp(r'([H][0-9]{7}X)$');

/// If there's no error, returns an empty [String]
/// If there's an error, returns an error [String]
static String checkForError(String stateCode, String licenseNumber) {
if (stateCode == null || licenseNumber == null) {
return "";
}

if (stateCode == 'AK') {
return _validateExpression(oneToSevenNumeric, licenseNumber, "Must be 1-7 numeric");
}

if (stateCode == 'AL') {
return _validateExpression(sevenNumeric, licenseNumber, "Must be 7 numeric");
}

if (stateCode == 'AR' || stateCode == 'MS') {
return _validateExpression(nineNumeric, licenseNumber, "Must be 9 numeric");
}

if (stateCode == 'AZ') {
if (nineNumeric.hasMatch(licenseNumber)) {
return "";
}

if (oneAlpha.hasMatch(licenseNumber) && eightAreNumbers.hasMatch(licenseNumber)) {
return "";
}

if (twoAlpha.hasMatch(licenseNumber) &&
threeToFiveNumeric.hasMatch(licenseNumber) &&
licenseNumber.length < 8) {
return "";
}

return "Must be 1 Alphabetic, 8 Numeric; or 2 Alphabetic, 3-6 Numeric; or 9 Numeric";
}

if (stateCode == 'CA') {
if (oneAlpha.hasMatch(licenseNumber) && oneAlphaPlusSeven.hasMatch(licenseNumber)) {
return "";
}

return "Must be 1 alpha and 7 numeric";
}

if (stateCode == 'CO' || stateCode == 'CN' || stateCode == 'CT') {
return _validateExpression(nineNumeric, licenseNumber, "Must be 9 numeric");
}

if (stateCode == 'DC') {
if (sevenNumeric.hasMatch(licenseNumber) || nineNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 7 - 9 numeric";
}

if (stateCode == 'DE') {
if (oneToSevenNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 1 - 7 numeric";
}

if (stateCode == 'FL') {
if (oneAlpha.hasMatch(licenseNumber) && twelveNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 1 alpha, 12 numeric";
}

if (stateCode == 'GA') {
if (sevenToNineNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 7 - 9 numeric";
}

if (stateCode == 'HI') {
if (nineNumeric.hasMatch(licenseNumber) || hPlusEight.hasMatch(licenseNumber)) {
return "";
}

return "Must 'H' + 8 numeric; 9 numeric";
}

if (stateCode == 'ID') {
if (nineNumeric.hasMatch(licenseNumber) ||
sixNumeric.hasMatch(licenseNumber) ||
(twoAlpha.hasMatch(licenseNumber) && alphaPlusSixNumeric.hasMatch(licenseNumber))) {
return "";
}

return "Must 9 numbers or 6 numbers; or 2 char, 6 numbers ";
}

if (stateCode == 'IL') {
if (oneAlpha.hasMatch(licenseNumber) && elevenNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must 1 character 11 numbers";
}

if (stateCode == 'IN') {
if (tenNumeric.hasMatch(licenseNumber) || nineNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 9-10 numbers";
}

if (stateCode == 'IA') {
if (nineAlphaChars.hasMatch(licenseNumber) || nineNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 9 alpha numbers";
}

if (stateCode == 'KS' || stateCode == 'KY') {
if (nineNumeric.hasMatch(licenseNumber) ||
(oneAlpha.hasMatch(licenseNumber) &&
eightAreNumbers.hasMatch(licenseNumber) &&
licenseNumber.length == 9)) {
return "";
}

return "Must be 1 alpha and 8 numeric";
}

if (stateCode == 'LA') {
if (nineNumeric.hasMatch(licenseNumber) == true) {
return "";
}

return "Must be 9 numeric";
}

if (stateCode == 'ME') {
if (sevenNumeric.hasMatch(licenseNumber) || sevenPlusX.hasMatch(licenseNumber)) {
return "";
}

return "Must be 7 numeric";
}

if (stateCode == 'MD' || stateCode == 'MI' || stateCode == 'MN') {
if (oneAlpha.hasMatch(licenseNumber) && twelveNumeric.hasMatch(licenseNumber)) {
return "";
}

return "1 Alphabetic, 12 Numeric";
}

if (stateCode == 'MA') {
if ((oneAlpha.hasMatch(licenseNumber) &&
eightAreNumbers.hasMatch(licenseNumber) &&
licenseNumber.length == 9) ||
nineNumeric.hasMatch(licenseNumber)) {
return "";
}

return "Must be 1 alpha, 8 numeric; 9 numeric";
}

if (stateCode == 'MO') {
if ((oneAlpha.hasMatch(licenseNumber) &&
fiveToNineNumeric.hasMatch(licenseNumber) &&
licenseNumber.length < 11) ||
nineNumeric.hasMatch(licenseNumber)) {
return "";
}

return "1 alpha - 5-9 Numeric or 9 numeric";
}

return "Invalid state code";
}

static String _validateExpression(RegExp expression, String value, String error) =>
expression.hasMatch(value) ? "" : error;
}

关于dart - Flutter/Dart 中的驾照验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55995832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com