mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 09:02:48 -05:00
Refactor email attributes (#1458)
* Add StrictEmailAddress attribute * Remove duplicate checks, use attributes instead * Rename EmailAddressListAttribute
This commit is contained in:
30
src/Core/Utilities/StrictEmailAddressAttribute.cs
Normal file
30
src/Core/Utilities/StrictEmailAddressAttribute.cs
Normal file
@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user