Validates that a property, field, or parameter contains a valid IP address. Supports both IPv4 and IPv6 address formats.
public class IPAddressAttribute : ValidationAttribute
bool TryIsValid(string value, out string errorMessage)Summary: Attempts to validate the specified string as an IP address using default validation settings.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid IP address; otherwise,false.
bool TryIsValid(string value, IPAddressAttribute attribute, out string errorMessage)Summary: Attempts to validate the specified string as an IP address using default validation settings.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid IP address; otherwise,false.
RequiredSummary: Gets or sets a value indicating whether the IP address value is required.
bool IsValid(object value)
Validates that a property, field, or parameter contains a valid ISO 4217 currency code. The value must be a three-character uppercase string (e.g., USD, EUR, GBP). Optionally validates against a specific set of allowed currency codes.
public class IsoCurrencySymbolAttribute : ValidationAttribute
IsoCurrencySymbolsSummary: Gets or sets an optional array of specific ISO currency codes that are allowed. If empty, all valid ISO currency codes from available cultures are accepted.
RequiredSummary: Gets or sets a value indicating whether the currency code value is required.
bool IsValid(object value)
Validates that a property or field contains a valid key string. By default, excludes spaces, periods, at signs, and apostrophes, and disallows strings starting with underscores. This attribute extends System.ComponentModel.DataAnnotations.StringAttribute with key-specific validation rules.
public class KeyStringAttribute : StringAttribute
bool TryIsValid(string value, out string errorMessage)Summary: Attempts to validate the specified string as a key string using default validation settings.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid key string; otherwise,false.
bool TryIsValid(string value, KeyStringAttribute attribute, out string errorMessage)Summary: Attempts to validate the specified string as a key string using default validation settings.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid key string; otherwise,false.
Extension methods for System.ComponentModel.DataAnnotations.RegularExpressionAttribute.
public static class RegularExpressionAttributeExtensions
string GetEscapedPattern(this RegularExpressionAttribute regularExpressionAttribute, bool ensureQuotes = True)Summary: Gets the escaped pattern from a
System.ComponentModel.DataAnnotations.RegularExpressionAttributesuitable for code generation.Parameters:
regularExpressionAttribute- The regular expression attribute.
ensureQuotes- If set to , ensures the result is wrapped in double quotes.Returns: The escaped pattern string.
Validates that a property, field, or parameter contains a string value meeting specified constraints. Supports validation of length, invalid characters, invalid prefixes, and regular expression patterns.
public class StringAttribute : ValidationAttribute
bool TryIsValid(string value, out string errorMessage)Summary: Attempts to validate the specified string using default validation settings.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is valid; otherwise,false.
bool TryIsValid(string value, StringAttribute attribute, out string errorMessage)Summary: Attempts to validate the specified string using default validation settings.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is valid; otherwise,false.
InvalidCharactersSummary: Gets or sets an array of characters that are not allowed in the string.
InvalidPrefixStringsSummary: Gets or sets an array of prefixes that the string cannot start with.
MaxLengthSummary: Gets or sets the maximum allowed length of the string.
MinLengthSummary: Gets or sets the minimum allowed length of the string.
RegularExpressionSummary: Gets or sets a regular expression pattern that the string must match. If set, the string will be validated against this pattern with a 2-second timeout.
RequiredSummary: Gets or sets a value indicating whether the string value is required.
bool IsValid(object value)
Validates that a property, field, or parameter contains a valid URI with an allowed scheme. Supports HTTP, HTTPS, FTP, FTPS, File, and OPC TCP schemes.
public class UriAttribute : ValidationAttribute
UriAttribute DefaultSummary: A default configuration that allows all URI schemes and does not require a value.
UriAttribute HttpOrHttpsSummary: A preset configuration that only allows HTTP and HTTPS schemes and requires a value.
UriAttribute OpcTcpSummary: A preset configuration that only allows OPC TCP scheme (opc.tcp://) URIs and requires a value.
bool IsValidHttpOrHttps(object value)Summary: Validates whether the specified value is a valid HTTP or HTTPS URI.
Parameters:
value- The value to validate.Returns:
trueif the value is a valid http:// or https:// URI; otherwise,false.
bool IsValidOpcTcp(object value)Summary: Validates whether the specified value is a valid OPC TCP URI.
Parameters:
value- The value to validate.Returns:
trueif the value is a valid opc.tcp:// URI; otherwise,false.
bool TryIsValid(string value, out string errorMessage)Summary: Attempts to validate the specified string as a URI using default validation settings (all schemes allowed).
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid URI; otherwise,false.
bool TryIsValid(string value, UriAttribute attribute, out string errorMessage)Summary: Attempts to validate the specified string as a URI using default validation settings (all schemes allowed).
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid URI; otherwise,false.
bool TryIsValidHttpOrHttps(string value, out string errorMessage)Summary: Attempts to validate the specified string as an HTTP or HTTPS URI.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid http:// or https:// URI; otherwise,false.
bool TryIsValidOpcTcp(string value, out string errorMessage)Summary: Attempts to validate the specified string as an OPC TCP URI.
Parameters:
value- The string value to validate.
errorMessage- When validation fails, contains a message describing the validation error.Returns:
trueif the value is a valid opc.tcp:// URI; otherwise,false.
AllowFileSummary: Gets or sets a value indicating whether the File scheme is allowed.
AllowFtpSummary: Gets or sets a value indicating whether the FTP scheme is allowed.
AllowFtpsSummary: Gets or sets a value indicating whether the FTPS scheme is allowed.
AllowHttpSummary: Gets or sets a value indicating whether the HTTP scheme is allowed.
AllowHttpsSummary: Gets or sets a value indicating whether the HTTPS scheme is allowed.
AllowOpcTcpSummary: Gets or sets a value indicating whether the OPC TCP scheme is allowed.
RequiredSummary: Gets or sets a value indicating whether the URI value is required.
bool IsValid(object value)