Code Monkey home page Code Monkey logo

Comments (1)

i4004 avatar i4004 commented on May 20, 2024

Example:

/// <summary>
/// Indicates that this property should be a valid email address
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class EMailAttribute : ValidationAttribute
{
	/// <summary>
	/// Initializes a new instance of the <see cref="EMailAttribute"/> class.
	/// </summary>
	/// <param name="errorMessage">The custom error message, should contain string table item key if 'isMessageFromStringTable' is true.</param>
	/// <param name="isMessageFromStringTable">if set to <c>true</c> then indicates that errorMessage is containing string table item key instead of string error message.</param>
	public EMailAttribute(string errorMessage = null, bool isMessageFromStringTable = true) : base(errorMessage, isMessageFromStringTable)
	{
	}

	/// <summary>
	/// Validates the specified property value.
	/// </summary>
	/// <param name="value">The object value.</param>
	/// <param name="propertyInfo">Information about the property containing this attribute.</param>
	/// <param name="resolver">The objects resolver, useful if you need to retrieve some dependencies to perform validation.</param>
	public override void Validate(object value, PropertyInfo propertyInfo, IDIResolver resolver)
	{
		if (!(value is string))
			return;

		if (StringHelper.ValidateEMail((string)value))
			return;

		TryThrowCustomOrStringTableException(resolver);

		throw new ModelValidationException($"Property '{propertyInfo.Name}' should be an email, actual value: '{value}'");
	}
}

from simplify.web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.