Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:38:38+00:00 2026-05-29T22:38:38+00:00

public class Test { [RelativeDateTimeValidator(-10, DateTimeUnit.Year, 10, DateTimeUnit.Year, ErrorMessage = Error)] public DateTime ADate

  • 0
public class Test 
{
    [RelativeDateTimeValidator(-10, DateTimeUnit.Year, 10, DateTimeUnit.Year, ErrorMessage = "Error")]
    public DateTime ADate { get; set; } 

    public void ValidateMyProperty() 
    {
        ADate = new DateTime(1900, 01, 01);

        ValidationResults vrs = Validation.Validate<Test>(this);
        foreach (var vr in vrs)
        {
            Print(vr.Message);
        }
    }
}

this displays

The value must fall within the range "-10"(Year) - "10(Year) relative to now

However, how do I diplay/access the error message that I have specified (ErrorMessage = “Error”)?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:38:39+00:00Added an answer on May 29, 2026 at 10:38 pm

    I think you are looking for the MessageTemplate attribute if you want to specify what the message they receive when validation fails. It allows replaceable tokens too.

    From documentation :

    public class Person
    {
      [RelativeDateTimeValidator(-120, DateTimeUnit.Year, -18, DateTimeUnit.Year,
               Ruleset="RuleSetA", MessageTemplate="Must be 18 years or older.")]
      public DateTime DateOfBirth
      {
        get
        {
          return dateOfBirth;
        }
      }
    }
    

    Message Template Tokens

    If the message template contains tokens (for example, “{0}”), the validator will replace these tokens with values when the ValidationResult is created. The tokens supported by the Relative Date Time Validator are listed in the following table.

    Token

    Meaning

    {0}

    This token represents the value of the object that is being validated. Although it can be useful to show the original value as a part of the validation message, you must be careful to avoid injection attacks by escaping any characters that can be used to attack the system that conveys the message to the user.

    {1}

    This token represents the key of the object that is being validated. When the validator is attached to a member of a type such as a property or a field, the key is set to the member name. When the validator is attached to an object, the key is null and the token is replaced by an empty string.

    {2}

    This token represents the tag that is specified on the validator instance. If no tag is supplied, the token is replaced by an empty string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Test { private static void funct(final int i) { new Thread(new Runnable()
public class Test { public static void main(String[] args) { int[] arr = new
public class Test { public static void main(String[] args) { } } class Outer
public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: public class Test { public static void Main() {
Take a look at this code: public class Test { public static void main(String...
public class Test { public static void main(String[] args){ if (5.0 > 5) //
This simple class public class Test<T> { public static void A(Window wa, Window wb)
I have written this piece of code public class Test{ public static void main(String[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.