ValidationAttribute.IsValid Method

Definition

Checks whether the specified object is valid.

Overloads

IsValid(Object)

Determines whether the specified value of the object is valid.

IsValid(Object, ValidationContext)

Validates the specified value with respect to the current validation attribute.

IsValid(Object)

Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs

Determines whether the specified value of the object is valid.

public virtual bool IsValid (object value);
public virtual bool IsValid (object? value);
public abstract bool IsValid (object value);

Parameters

value
Object

The value of the object to validate.

Returns

true if the specified value is valid; otherwise, false.

Exceptions

The current attribute is malformed.

Neither overload of IsValid has been implemented by a derived class.

Remarks

If you inherit from the ValidationAttribute class, you must implement the validation logic in this method.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0

IsValid(Object, ValidationContext)

Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs

Validates the specified value with respect to the current validation attribute.

protected virtual System.ComponentModel.DataAnnotations.ValidationResult IsValid (object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);
protected virtual System.ComponentModel.DataAnnotations.ValidationResult? IsValid (object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);

Parameters

value
Object

The value to validate.

validationContext
ValidationContext

The context information about the validation operation.

Returns

An instance of the ValidationResult class.

Exceptions

The current attribute is malformed.

IsValid(Object, ValidationContext) has not been implemented by a derived class.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0