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 502291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:16:35+00:00 2026-05-13T06:16:35+00:00

How are people doing their validations on data? Basically I have a requirement that

  • 0

How are people doing their validations on data?

Basically I have a requirement that to apply for insurance you need to be over 14 years of age.

Now, on the application form you may need to not only enter your age but any nominated drivers date of births as well.

I went through the Nerd Dinner example and it works but I was wondering whether anyone is doing other types of validations.

  • 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-13T06:16:35+00:00Added an answer on May 13, 2026 at 6:16 am

    You can use DataAnnotations to attach validation to objects directly.

    Validating with Data Annotation Validators

    You can get fancy by creating custom data annotations which will then allow you to create validation on fields of a certain type.

    So for your age requirement;

    So;

    public class IsApplicantOldEnoughAttribute : ValidationAttribute
    {
        public override bool IsValid(object value)
        {
            if (value == null) return false;
            DateTime enteredDate = (DateTime)value;
    
            if ((DateTime.Today.Year - enteredDate.Year) >= 14)
                return true;
            else
                return false;
        }
    }
    

    Your model could then decorate the field;

    [IsApplicantOldEnough(ErrorMessage="Applicant must be over 14 years of age")]
    [Required]
    public DateTime DateOfBirth { get; set; }
    

    Then in your view;

    <p>
      <label for="UnitPrice">DOB:</label>
      <%= Html.TextBox("DateOfBirth")%>
      <%= Html.ValidationMessage("DateOfBirth", "*")%>
    </p>
    

    Then your Controller could look like this;

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Apply([Bind(Exclude = "Id")]Applicant newApplicant)
    {
      if (!ModelState.IsValid)
        return View();
    
      return RedirectToAction("Success");
    }
    

    This is a bit more work but you no longer need to call a method yourself everytime you wanted to validate some data.

    It also means that all applications that use this model will apply the same business rule to your ages thus providing consistency across the organisation.

    I actually happened to have the above handy to some respect. I use it a lot in my objects. Do remember to wrap this in a Try / Catch.

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

Sidebar

Ask A Question

Stats

  • Questions 245k
  • Answers 245k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why do you want to do this? The reason I… May 13, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer Yeah, you just need to add a TextChangedListener: textEdit.addTextChangedListener(new TextWatcher(){… May 13, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer It doesn't work as you expect because the 'wrapper' that… May 13, 2026 at 8:12 am

Related Questions

I've been using MVC frameworks for a short while now and I really like
For a normal Flash/Flex application I would include my Unit Tests in my application
Wondering how much effort I should go to forcing useful debugging information when creating
I have a subversion repository with the standard layout, i.e. trunk/ and branches/ (and
There are a number of ways to compare strings. Are there performance gains by

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.