I have a requirement where I need Birthdate field on contact to validate so that it does not exceeds today's date. Below is the code:

<lightning:input  value="{!v.objContact.Birthdate}" label="Date of Birth"/>

Can anyone let me know how to achieve this with javascript validation or any other method.


1 Answer 1


You should add these in your codes;


<lightning:input type="date" value="{!v.objContact.Birthdate}" label="Date of Birth" onchange="{!c.dateController}"/>

//JS Controller

 dateController : function(component, event, helper){
    var today = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD");
    var dateValue = component.get("v.objContact.Birthdate");

    if(dateValue > today){
        alert('You can not enter grater than today!');
        dateValue = null;
        component.set("v.objContact.Birthdate", dateValue);
  • I tried formatting the date format to "DD/MM/YYYY" but it doesn't work. Puzzled why only your "YYYY-MM-DD" works.
    – compski
    Jan 10, 2020 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.