是否有人知道可以在flutter项目中使用的API或程序包,该API或程序包可以让我检查驾驶执照号是否有效?如果有帮助,我正在与美国驾驶执照合作。
答案 0 :(得分:1)
似乎还没有插件,但是由于在大多数语言中可以完全相同的方式完成,因此已经完成了。看看: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;
}