LicenseplateValidator 1.0.0

dotnet add package LicenseplateValidator --version 1.0.0                
NuGet\Install-Package LicenseplateValidator -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LicenseplateValidator" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LicenseplateValidator --version 1.0.0                
#r "nuget: LicenseplateValidator, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LicenseplateValidator as a Cake Addin
#addin nuget:?package=LicenseplateValidator&version=1.0.0

// Install LicenseplateValidator as a Cake Tool
#tool nuget:?package=LicenseplateValidator&version=1.0.0                

LicenseplateValidator

Fun little brain teaser turned into a small library

Main methods:

var lpv = new LicensePlateValidator(); // By default only knows about dutch license plate formats ("sidecodes")

lpv.IsValidPlate("AB-12-CD", "NL");  // Returns true
lpv.FormatPlate("AB12CD", "NL");     // Returns "AB-12-CD"
lpv.FindSideCode("AB12CD", "NL");    // Returns "XX-99-XX"

Most methods have a ignoreDashes argument; when true, dashes in the input are ignored. When false, dashes should be in the correct place.

target.IsValidPlate("AB12CD", "NL", ignoreDashes: false);    // Returns false
target.IsValidPlate("AB-12-CD", "NL", ignoreDashes: false);  // Returns true

target.IsValidPlate("AB12CD", "NL", ignoreDashes: true);     // Returns true
target.IsValidPlate("AB-12-CD", "NL", ignoreDashes: true);   // Returns true

Most methods will throw on errors; there are Try... methods that will not throw on common errors (unless documented).

Other countries / sidecodes:

The LicensePlateValidator supports other countries. All you need to do is pass in the allowed sidecodes. These are codes like XX-99-XX which describe where digits (9), letters (X), digit or letter (?) and dashes (-) should go in a plate. You can specify these, along with the country codes, in the constructor:

var lpv = new LicenseplateValidator(new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
{
    { "XX", new[] { "XX-99-XX", "X9-9X-X9", "99-X-99X" } },
    { "YY", new[] { "99-XX-99", "XXX-999" } }
});

The above initializes a new LicenseplateValidator with two fictional countries ("XX" and "YY") with the sidecodes for each country. Note that because we use an overload of the dictionary that makes the key comparer case-insensitive you can pass "XX", "Xx", "xX" or "xx" as countrycode to all methods and this will work fine. If you don't want this behaviour then simply use the parameterless dictionary constructor or pass any other IDictionary<string, string[]> that implements the desired key comparison. Also note that you don't HAVE to stick with country codes like "NL", "XX" etc. You can use whatever key you like.

About actual validation

This project / library was born out of a little brainteaser that got a little out of hand. However; that doesn't mean in any way that this library is 100% correct. In fact, it doesn't even make any attempt to be correct. For example, ANY letter will be allowed where some sidecodes don't allow certain letters (like the letter C which isn't valid in Sidecode 1). Also some letters/digits are only allowed in certain places. All these minor details have not been added to this library. This is a quick'n'dirty fun little project that works fine for most purposes. If you want all the nitty gritty details supported or implemented then I suggest you look elsewhere (or make a pull request 😉). Methods like IsValid() therefore only return a 'minimal effort' result, an 'estimate' of whether a plate could be valid.

<hr>

Icon made by Freepik from www.flaticon.com is licensed by CC 3.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 258 1/18/2022