mirror of
https://github.com/bitwarden/server.git
synced 2026-02-09 02:13:11 +08:00
31 lines
808 B
C#
31 lines
808 B
C#
|
|
using System;
|
|||
|
|
using System.ComponentModel.DataAnnotations;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
|
|||
|
|
namespace Bit.Core.Utilities
|
|||
|
|
{
|
|||
|
|
public class StrictEmailAddressAttribute : ValidationAttribute
|
|||
|
|
{
|
|||
|
|
public StrictEmailAddressAttribute()
|
|||
|
|
: base("The {0} field is not a valid e-mail address.")
|
|||
|
|
{}
|
|||
|
|
|
|||
|
|
public override bool IsValid(object value)
|
|||
|
|
{
|
|||
|
|
var emailAddress = value?.ToString();
|
|||
|
|
if (emailAddress == null)
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var illegalChars = @"[\s<>()]";
|
|||
|
|
if (Regex.IsMatch(emailAddress, illegalChars))
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return new EmailAddressAttribute().IsValid(emailAddress);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|