Ashwanikumar singh

Ashwanikumar singh

  • 1.9k
  • 39
  • 30.9k

Asp.net MVC Date validation

Dec 5 2017 12:39 PM
I like to cover all validations on my form but when it comes to date field i always struggle.
And here i am again. 
I have 2 Date field :
1. Date of Birth
2. Date of anniversary
 
The validations i want is:
1) Date of birth must be 10 years back only from current date (i am not checking age for 18 years,i just want in my DOB field 10 years back date must be selected ).
 
2)And the anniversary date must be greater than Date of birth
3)since both are date field , in my textbox its accepting digits like : 12345656 .
   It musts accept only date.
 
here is my model class :
 
namespace test.Models
{
public class Student
{
   [Required(ErrorMessage ="Date of birth is required")]
   [DataType(DataType.Date)]
   public string DOB { get; set; }

   [Required(ErrorMessage = "Date of anniversary is required")]
   [DataType(DataType.Date)]
   public string DOA { get; set; }
}
 
I am asking for big but its not allowing me to sleep.
If anybody can help. Thanks in advance !!!!

Brought to you by:

Answers (2)