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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:16:04+00:00 2026-05-26T10:16:04+00:00

I got 2 DateTime field and i use datepicker for user to choose a

  • 0

I got 2 DateTime field and i use datepicker for user to choose a date. However, since it is a textbox, user can still enter any value and click the submit button. So, I wish to have validation on the DateTime textfield to check whether the value submitted is a DateTime with specific format. I tried this:

[Required(ErrorMessage = "Storage Date is required")]
[DataType(DataType.DateTime, ErrorMessage = "Please input a valid date")]
public DateTime StorageDate { get; set; }

However, I dint get any message even i input “xxxxx” in the textbox and submit (Note: the [Required] validation do work)

My form is like this:

<div class="editor-label">
    Storage Date
</div>
<div class="editor-field">
    @Html.TextBox("StorageDate", String.Format("{0:ddd, d MMM yyyy}", DateTime.Now), new { id = "storagedate" })
    @Html.ValidationMessageFor(model => model.StorageDate)
</div>

So, I need check the Date according to the format also.. Any idea why it is not working???

Any help is really appreciated…Thanks…

  • 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-26T10:16:05+00:00Added an answer on May 26, 2026 at 10:16 am

    You could add a regular expression annotation to the property of your view model:

    [RegularExpression("Expression_goes_here", "Date is of invalid format.")]
    

    Here is a link for a REGEX library – you may choose to use one of their expressions for validating date.

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

Sidebar

Related Questions

How could we handle null for a datetime field (got from SQL Server) in
I've got a DateTime? that I'm trying to insert into a field using a
I got an field named last in MySQL, it has an attribute: datetime so
Use a hidden field will fix my issue... i got it.. Hi All, I
I've got a table with an auto-increment number field As No, a date/time stamp
I've got a field on a class that should set the current date correctly:
I have a datetime field in a Sybase table, and need to use it
I've got this date time string: post[date] = 2007-07-18 10:03:19 I'd like to extract
I've got a pointer to a string, (char *) as input. The date/time looks
I have a datetime field and I want to count all records by day

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.