Hi Guys,
I have a Age Field & D.O.B Field.Already am write a javascript for Calculating Age.But Now I Want to Validate date of Birth Field How to Validate the Field Using JavaScript.
Thank You
*This post is locked for comments

Hi Guys,
I have a Age Field & D.O.B Field.Already am write a javascript for Calculating Age.But Now I Want to Validate date of Birth Field How to Validate the Field Using JavaScript.
Thank You
*This post is locked for comments
Hi
What do you want to validate?
Do you want to validate to make sure that the date is in a particular range?
D.O.B should accept the date since the current date
Compare it with the current date. Something like
dob < new Date()
its not working..
HI
Please copy the full code here
var BirthDate = Xrm.Page.getAttribute("tkcg_dob").getValue();
var Today = new Date();
if (BirthDate > Today) {
alert('Date of birth can not be greater than the date today');
Xrm.Page.getAttribute("tkcg_dob").setValue(); //set null value
}
Hi
What is the Behavior and Format of the date field tkcg_dob?
You can also check the value of DOB when you enter a date value in that field when debugging.
Today has the time component, so when both dates are equal it will not work properly as compare compares both date and time.
Or you can change the code
if(BirthDate < Today)
{
//do something
}
else
{
alert('Date of birth can not be greater than the date today');
Xrm.Page.getAttribute("tkcg_dob").setValue(null); //set null value
}
try to write last line of code like below
Xrm.Page.getAttribute("tkcg_dob").setValue()=null; //set null value
If you have issue only with clearing the date field, you can use as below:
Xrm.Page.getAttribute("tkcg_dob").setValue(null); //set null value