web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Date of Birth Validation

(0) ShareShare
ReportReport
Posted on by

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

  • Gopalan Bhuvanesh Profile Picture
    on at
    RE: Date of Birth Validation

    Hi

    What do you want to validate?

    Do you want to validate to make sure that the date is in a particular range?

  • DineshRaja Profile Picture
    on at
    RE: Date of Birth Validation

    D.O.B should accept the date since the current date

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Date of Birth Validation

    Compare it with the current date. Something like

    dob < new Date()

  • Suggested answer
    Community Member Profile Picture
    on at
  • DineshRaja Profile Picture
    on at
    RE: Date of Birth Validation

    its not working..

  • Gopalan Bhuvanesh Profile Picture
    on at
    RE: Date of Birth Validation

    HI

    Please copy the full code here

  • DineshRaja Profile Picture
    on at
    RE: Date of Birth Validation

    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

      }

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    on at
    RE: Date of Birth Validation

    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

    }

  • Samrando Profile Picture
    on at
    RE: Date of Birth Validation

    try to write last  line of code like below

         Xrm.Page.getAttribute("tkcg_dob").setValue()=null; //set null value

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    on at
    RE: Date of Birth Validation

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans