diff --git a/IdParser.Test/DriversLicenseTests.cs b/IdParser.Test/DriversLicenseTests.cs index 6f4de01..39d4ae2 100644 --- a/IdParser.Test/DriversLicenseTests.cs +++ b/IdParser.Test/DriversLicenseTests.cs @@ -2320,5 +2320,56 @@ public void TestILLicense() Assert.AreEqual("60611", idCard.Address.PostalCodeDisplay); Assert.AreEqual("Illinois", idCard.IssuerIdentificationNumber.GetDescription()); } + + [TestMethod] + public void TestHILicense() + { + var expected = new DriversLicense + { + Name = new Name + { + First = "MICHAEL", + Middle = "JAY", + Last = "MOTORIST" + }, + + Address = new Address + { + StreetLine1 = "456 MOANA ST 2", + StreetLine2 = "O", + City = "HONOLULU", + JurisdictionCode = "HI", + PostalCode = "96826", + Country = Country.Usa + }, + + DateOfBirth = new DateTime(1988, 03, 12), + Sex = Sex.Male, + EyeColor = EyeColor.Blue, + HairColor = HairColor.Blond, + Height = Height.FromImperial(72), + + IdNumber = "H01387330", + AamvaVersionNumber = Version.Aamva2009, + + IssueDate = new DateTime(2016, 05, 13), + ExpirationDate = new DateTime(2024, 03, 12), + + Jurisdiction = new DriversLicenseJurisdiction + { + VehicleClass = "3", + RestrictionCodes = "B" + } + }; + + var file = File.ReadAllText("HI License.txt"); + var idCard = Barcode.Parse(file, Validation.None); + + AssertIdCard(expected, idCard); + AssertLicense(expected, idCard); + + Assert.AreEqual("96826", idCard.Address.PostalCodeDisplay); + Assert.AreEqual("Hawaii", idCard.IssuerIdentificationNumber.GetDescription()); + } } } diff --git a/IdParser.Test/HI License.txt b/IdParser.Test/HI License.txt new file mode 100644 index 0000000..b631579 --- /dev/null +++ b/IdParser.Test/HI License.txt @@ -0,0 +1,30 @@ +@ + +ANSI 636047040002DL00410258ZH02990021DLDCA3 +DCBB +DCDNONE +DBA03122024 +DCSMOTORIST +DACMICHAEL +DADJAY +DBD05132016 +DBB03121988 +DBC1 +DAYBLU +DAU72 IN +DAG456 MOANA ST 2 +DAIHONOLULU +DAJHI +DAK96826 0 +DAQH01387330 +DCF2016051411385491547K1O +DCGUSA +DDEU +DDFU +DDGU +DAHO +DAZBLN +DCJ20160518-053221-9-2048 +ZHZHAO +ZHB +ZHCHIDL-C diff --git a/IdParser.Test/IdParser.Test.csproj b/IdParser.Test/IdParser.Test.csproj index 466f688..a90aebc 100644 --- a/IdParser.Test/IdParser.Test.csproj +++ b/IdParser.Test/IdParser.Test.csproj @@ -68,6 +68,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/IdParser/Parsers/Id/PostalCodeParser.cs b/IdParser/Parsers/Id/PostalCodeParser.cs index 52d9955..af2edac 100644 --- a/IdParser/Parsers/Id/PostalCodeParser.cs +++ b/IdParser/Parsers/Id/PostalCodeParser.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System; +using System.Text.RegularExpressions; using IdParser.Attributes; namespace IdParser.Parsers.Id @@ -14,11 +15,19 @@ public PostalCodeParser(IdParser.IdentificationCard idCard, Version version, Cou public override void ParseAndSet(string input) { - if (input == null) + if (StringHasNoValue(input)) { return; } + // Some jurisdictions, like Hawaii, have spaces after the ZIP code followed by a number like 0. + // Chop off the excess junk otherwise we'd wind up with a 6-digit ZIP code. + var indexOfSpaces = input.IndexOf(" ", StringComparison.OrdinalIgnoreCase); + if (indexOfSpaces >= 0) + { + input = input.Substring(0, indexOfSpaces); + } + IdCard.Address.PostalCode = new Regex(NonAlphaNumericPattern).Replace(input, "") .Replace("0000", ""); } diff --git a/README.md b/README.md index 8835e30..c5903b4 100644 --- a/README.md +++ b/README.md @@ -54,4 +54,10 @@ will be parsed correctly. The app works with both OPOS and HID keyboard emulatio recommended level for scanners using OPOS. However, if HID keyboard emulation is used, especially when scanning using a web browser, the expected data can become malformed. You can try using the `None` validation level, however this is not guaranteed to work in all cases. Data elements may be skipped - and exceptions may still be thrown. \ No newline at end of file + and exceptions may still be thrown. + +## Find IDs Not in Tests Regex + +```regex +DAJ(?!(AL|AR|AZ|CA|CO|CT|DE|FL|GA|IA|IL|IN|KS|KY|LA|MA|MD|ME|MI|MO|MT|NC|NH|NJ|NM|NY|OH|ON|OR|PA|PR|RI|SC|TN|TX|UT|VA|VT|WA|WI|QC|OK))[A-Z]+ +```