Rijnbout.Validators 2.0.0

dotnet add package Rijnbout.Validators --version 2.0.0                
NuGet\Install-Package Rijnbout.Validators -Version 2.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="Rijnbout.Validators" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rijnbout.Validators --version 2.0.0                
#r "nuget: Rijnbout.Validators, 2.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 Rijnbout.Validators as a Cake Addin
#addin nuget:?package=Rijnbout.Validators&version=2.0.0

// Install Rijnbout.Validators as a Cake Tool
#tool nuget:?package=Rijnbout.Validators&version=2.0.0                

The validators project is meant to supply functionality to easily validate (user) input to prevent insertion of potentially harmful content without restricting user input too much. Many sites are vulnerable for XSS or injection attacks (see OWASP top 10). By using whitelisting for all your user input it is easy to prevent most injection issues. Using too restricted whitelists can however prevent users from inputting the data they want. If a user cannot input his or her name because it contains some characters not in the whitelist, you don't have a proper balance between security and user friendliness. This project is meant to help maintain the proper balance. Good security without annoying users bij restricting input too much.

Available Validators

In the current version the following validators are available:

  1. TextValidator
  2. ExtendedTextValidator
  3. MultiLineTextValidator
  4. NameValidator
  5. TelephoneNumberValidator
  6. EmailAddressValidator

TextValidator

Provides validation functions for basic (letters only) text input. With this validator you can check if your input consists of only Unicode letters. You can set if spaces are allowed (default spaces are not allowed).

ExtendedTextValidator

Provides validation functions for extended (letters and numbers) text input. With this validator you can check if your input consists of only letters, digits _ and -. You can set if spaces are allowed (default spaces are allowed).

MultiLineTextValidator

Provides validation functions for multi-line text input. With this validator allows letters, digits, line breaks, quotes, punctuation, url's and email adresses.

NameValidator

Provides validation functions for human names, only characters normally used in human names are allowed (whitelisted) when validating using this validator. You can set if single quotes are allowed in names (for names like O'Reilly).

TelephoneNumberValidator

Provides validation functions for telephone numbers, only digits, spaces, +, -, ( and ) are allowed (whitelisted) when validating using this validator.

EmailAddressValidator

Provides validation functions for email addresses. You can set wether only basic latin is allowed or also other alphabets.

Creation

Simply create an instance of the right class and reuse it for all calls within your preferred scope. The constructor allows you to set the available options for all validation actions performed by the created instance. You can create validation instances for a single page or for your entire application.

bool allowSingleQuotes = false;
var validator = new NameValidator(allowSingleQuotes);

Using Dependency Injection Containers

If you use an IoC or Dependency Injection Container (like AutoFac) you can create your validator instances and then registering them for further use in your entire application. This way you can define the options for your validators at one point and reuse validators with those options throughout your application.

var builder = new ContainerBuilder();
var nameValidator = new NameValidator(false);
builder.RegisterInstance(nameValidator).As<NameValidator>();

Usage

All validators have the following 2 methods:

  1. IsValid(string value) ⇒ bool
  2. RemoveInvalidCharacters(string value) ⇒ string

A basic implementation would be the following.

if (!validator.IsValid(inputValue))
{
    // Do something if input is invalid
}

You could also just remove the invalid input, make sure you communicate to the user that the input is invalid and why it is invalid.

if (!validator.IsValid(inputValue))
{
    inputValue = validator.RemoveInvalidCharacters(inputValue);

    // Return a validation message
}
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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.4 is compatible.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net451 is compatible.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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.

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
2.0.0 1,191 1/3/2018
1.1.0 1,445 10/22/2017
1.0.0 1,150 8/19/2017
0.1.2 937 7/1/2017
0.1.2-alpha 790 7/1/2017
0.1.1 908 7/1/2017
0.1.0 896 6/28/2017

Added Telephone Number validator
   Added Email Address validator
   Allow extra characters for MultiLine Text validator (currency symbols and hashtag)
   Fix documentation typo