Class Validation
Validation methods for DataTables Editor fields. All of the methods defined in this class return a delegate that can be used by
Field
instance's Validator
method.
Each method may define its own parameters that configure how the
formatter operates. For example the minLen
validator takes information
on the minimum length of value to accept.
Additionally each method can optionally take a
ValidationOpts
instance that controls common validation options and error messages.
The validation delegates return null
for validate data and a string for
invalid data, with the string being the error message.
Inheritance
Namespace: DataTables
Assembly: DataTables-Editor-Server.dll
Syntax
public class Validation : object
Methods
| Improve this Doc View SourceBasic(ValidationOpts)
Basic validation - this is used to perform the validation provided by the
validation options only. If the validation options pass (e.g. required
,
empty
and optional
) then the validation will pass regardless of the
actual value.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Basic(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Boolean(ValidationOpts)
Validate an input as a boolean value.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Boolean(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
DateFormat(String, ValidationOpts)
Check that a valid date input is given
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> DateFormat(string format, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
format | Format that the date / time should be given in |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
DbValues(ValidationOpts, String, String, Database, IEnumerable<Object>)
Check that the given value is a value that is available in a database -
i.e. a join primary key. This will attempt to automatically use the table
name and value column from the field's Options
method (under the
assumption that it will typically be used with a joined field), but the
table and field can also be specified via the options.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> DbValues(ValidationOpts cfg = null, string column = null, string table = null, Database db = null, IEnumerable<object> valid = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
System. |
column | Column name to use to check as a unique value. If not given the host field's database column name is used |
System. |
table | Table to check that this value is uniquely valid on. If not given the host Editor's table name is used |
Database | db | Database connection. If not given the host Editor's database connection is used |
IEnumerable<System. |
valid | List of values that are valid in addition to the values found via the database |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Email(ValidationOpts)
Validate an input as an e-mail address.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Email(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
FileExtensions(IEnumerable<String>, String)
File extension validation
Declaration
public static Func<Microsoft.AspNetCore.Http.IFormFile, string> FileExtensions(IEnumerable<string> extensions, string msg = "Invalid file type.")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System. |
extensions | List of extensions that are allowed. This is case insensitive. |
System. |
msg | Error message if validation fails. |
Returns
Type | Description |
---|---|
Func<Microsoft. |
File validation delegate |
FileSize(Int32, String)
File size upload validation method
Declaration
public static Func<Microsoft.AspNetCore.Http.IFormFile, string> FileSize(int size, string msg = "Uploaded file is too large.")
Parameters
Type | Name | Description |
---|---|---|
System. |
size | Max file size in bytes |
System. |
msg | Error message if validation fails. |
Returns
Type | Description |
---|---|
Func<Microsoft. |
File validation delegate |
Ip(ValidationOpts)
Validate as an IP address.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Ip(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MaxLen(Int32, ValidationOpts)
Validate a string does not exceed a maximum length.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MaxLen(int max, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
max | Maximum length |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MaxNum(Decimal, ValidationOpts)
Check for a numeric input and that it is less than a given value.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MaxNum(decimal max, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
max | Maximum value the numeric value can take |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MaxNum(Decimal, String, ValidationOpts)
Check for a numeric input and that it is less than a given value.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MaxNum(decimal max, string culture = "en-US", ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
max | Maximum value the numeric value can take |
System. |
culture | Numeric conversion culture |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MinLen(Int32, ValidationOpts)
Validate a string has a minimum length.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MinLen(int min, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
min | Minimum length |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MinMaxLen(Int32, Int32, ValidationOpts)
Require a string with a certain minimum or maximum number of characters.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MinMaxLen(int min, int max, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
min | Minimum length |
System. |
max | Maximum length |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MinMaxNum(Decimal, Decimal, ValidationOpts)
Check for a numeric input and that it is both less than and greater than given values
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MinMaxNum(decimal min, decimal max, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
min | Minimum value the numeric value can take |
System. |
max | Maximum value the numeric value can take |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MinMaxNum(Decimal, Decimal, String, ValidationOpts)
Check for a numeric input and that it is both less than and greater than given values
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MinMaxNum(decimal min, decimal max, string culture = "en-US", ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
min | Minimum value the numeric value can take |
System. |
max | Maximum value the numeric value can take |
System. |
culture | Numeric conversion culture |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MinNum(Decimal, ValidationOpts)
Check for a numeric input and that it is greater than a given value.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MinNum(decimal min, ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
min | Minimum value the numeric value can take |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MinNum(Decimal, String, ValidationOpts)
Check for a numeric input and that it is greater than a given value.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> MinNum(decimal min, string culture = "en-US", ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
min | Minimum value the numeric value can take |
System. |
culture | Numeric conversion culture |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
MjoinMaxCount(Int32, String)
Mjoin maximum number of selected values validation
Declaration
public static Func<Editor, DtRequest.RequestTypes, Dictionary<string, object>, string> MjoinMaxCount(int count, string msg = "Too many items")
Parameters
Type | Name | Description |
---|---|---|
System. |
count | Maximum number of items required. |
System. |
msg | Error message if validation fails. |
Returns
Type | Description |
---|---|
Func<Editor, Dt |
Mjoin validation delegate |
MjoinMinCount(Int32, String)
Mjoin minimum number of selected values validation
Declaration
public static Func<Editor, DtRequest.RequestTypes, Dictionary<string, object>, string> MjoinMinCount(int count, string msg = "Too few items")
Parameters
Type | Name | Description |
---|---|---|
System. |
count | Minimum number of items required. |
System. |
msg | Error message if validation fails. |
Returns
Type | Description |
---|---|
Func<Editor, Dt |
Mjoin validation delegate |
None(ValidationOpts)
No validation - all inputs are valid.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> None(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
NoTags(ValidationOpts)
Ensure that the submitted string does not contain HTML tags
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> NoTags(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
NotEmpty(ValidationOpts)
Optional field, but if given there must be a non-empty value
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> NotEmpty(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Numeric(String, ValidationOpts)
Check that any input is numeric.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Numeric(string culture = "en-US", ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
culture | Numeric conversion culture |
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Required(ValidationOpts)
Required field - there must be a value and it must be a non-empty value
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Required(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Unique(ValidationOpts, String, String, Database)
Check that the given value is unique in the database
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Unique(ValidationOpts cfg = null, string column = null, string table = null, Database db = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
System. |
column | Column name to use to check as a unique value. If not given the host field's database column name is used |
System. |
table | Table to check that this value is uniquely valid on. If not given the host Editor's table name is used |
Database | db | Database connection. If not given the host Editor's database connection is used |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Unique<T>(ValidationOpts, String, String, Database)
Check that the given value is unique in the database
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Unique<T>(ValidationOpts cfg = null, string column = null, string table = null, Database db = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
System. |
column | Column name to use to check as a unique value. If not given the host field's database column name is used |
System. |
table | Table to check that this value is uniquely valid on. If not given the host Editor's table name is used |
Database | db | Database connection. If not given the host Editor's database connection is used |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Type Parameters
Name | Description |
---|---|
T | Type to be used for the query condition value |
Url(ValidationOpts)
Validate as an URL address.
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Url(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Values(ValidationOpts, IEnumerable<Object>)
Confirm that the value submitted is in a list of allowable values
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Values(ValidationOpts cfg = null, IEnumerable<object> valid = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
IEnumerable<System. |
valid | List of values that are valid |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |
Xss(ValidationOpts)
Check if string could contain an XSS attack string
Declaration
public static Func<object, Dictionary<string, object>, ValidationHost, string> Xss(ValidationOpts cfg = null)
Parameters
Type | Name | Description |
---|---|---|
Validation |
cfg | Validation options |
Returns
Type | Description |
---|---|
Func<System. |
Validation delegate |