Try our conversational search powered by Generative AI!

Class Validator

Contains validation methods

Inheritance
System.Object
Validator
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Framework
Assembly: EPiServer.Framework.dll
Version: 11.20.7
Syntax
public static class Validator

Fields

DefaultEmailRegexString

The default string used for validation of email adresses.

Declaration
public const string DefaultEmailRegexString = "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$"
Field Value
Type Description
System.String
Remarks

The difference between this and EmailRegexString is that the later can be changed during the lifetime of the application.

DefaultMultipleEmailRegexString

The default string used for validation of multiple email adresseses.

Declaration
public const string DefaultMultipleEmailRegexString = "^([a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?[,][\\040]?)*([a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]))$"
Field Value
Type Description
System.String
Remarks

The difference between this and MultipleEmailRegexString is that the later can be changed during the lifetime of the application.

Properties

EmailRegex

Gets the email regex that is used for EPiServer products.

Declaration
public static Regex EmailRegex { get; }
Property Value
Type Description
System.Text.RegularExpressions.Regex

The email regex that is used for EPiServer products.

Remarks

If you want to change the regular expression used then set the EmailRegexString to your own regex.

EmailRegexString

Gets or sets the email regex string that is used validating email addresses in EPiServer products.

Declaration
public static string EmailRegexString { get; set; }
Property Value
Type Description
System.String

The email regex string that is used validating email addresses in EPiServer products.

Remarks

Note that the regex should handle casing since case sensivity is not supported by the RegularExpressionValidator control.

MultipleEmailRegex

Gets the regular expression for multiple email addresses that is used for EPiServer products.

Declaration
public static Regex MultipleEmailRegex { get; }
Property Value
Type Description
System.Text.RegularExpressions.Regex

The email regex that is used to validate multiple email addresses for EPiServer products.

Remarks

If you want to change the regular expression used then set the MultipleEmailRegexString to your own regex.

MultipleEmailRegexString

Gets or sets the email regex string that is used validating multiple email addresses in EPiServer products.

Declaration
public static string MultipleEmailRegexString { get; set; }
Property Value
Type Description
System.String

The email regex string that is used validating multiple email addresses in EPiServer products.

Remarks

Note that the regex should handle casing since case sensivity is not supported by the RegularExpressionValidator control.

Methods

ThrowIfContainsSqlInjectionChars(String, String)

Throws an System.ArgumentException if contains potential SQL injection code

Declaration
public static void ThrowIfContainsSqlInjectionChars(string name, string value)
Parameters
Type Name Description
System.String name

The name of the argument

System.String value

The value to check

Exceptions
Type Condition
System.ArgumentException

Thrown if the value contains potential SQL injection code

ThrowIfInvalidLength(String, String, Int32, Int32)

Throws an System.ArgumentException if has a length shorter than or longer than

Declaration
public static void ThrowIfInvalidLength(string name, string value, int minLength, int maxLength)
Parameters
Type Name Description
System.String name

The name of the argument

System.String value

The value to check

System.Int32 minLength

The minimum length the string can be

System.Int32 maxLength

The maximum length the string can be

Exceptions
Type Condition
System.ArgumentNullException

Thrown if the value to check is null or empty string

System.ArgumentException

If the length requirements are not met

ThrowIfInvalidSqlIdentifier(IEnumerable<String>)

Declaration
public static void ThrowIfInvalidSqlIdentifier(IEnumerable<string> identifiers)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.String> identifiers

ThrowIfNull(String, Object)

Throws an System.ArgumentNullException if is null

Declaration
public static void ThrowIfNull(string name, object value)
Parameters
Type Name Description
System.String name

The name of the argument

System.Object value

The value to check

Exceptions
Type Condition
System.ArgumentNullException

Thrown if the value to check is null

ThrowIfNullOrEmpty(String, String)

Throws an System.ArgumentNullException if is null or System.String.Empty

Declaration
public static void ThrowIfNullOrEmpty(string name, string value)
Parameters
Type Name Description
System.String name

The name of the argument

System.String value

The value to check

Exceptions
Type Condition
System.ArgumentNullException

Thrown if the value to check is null or empty string