21 lines
677 B
C#
21 lines
677 B
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace ValidationWebSite
|
|
{
|
|
public class CompanyNameAttribute : ValidationAttribute
|
|
{
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
{
|
|
var valueString = value as string;
|
|
if (string.IsNullOrEmpty(valueString))
|
|
{
|
|
return new ValidationResult("CompanyName cannot be null or empty.");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
} |