'How to restrict user below 18 years to not register using reactjs datepicker?

I have successfully implemented the react js datepicker. Now I want to restrict users below 18 years to not register.

This is my datepicker

<DatePicker
 selected={this.state.dob}
 onChange={this.dateChange}
 className="form-control"
 maxDate={new Date()}
 />

Suggest me what to do. Thank You!



Solution 1:[1]

I have just added "this" to work in desired scope.
Modified code:

const ageRestriction = new Date().setFullYear(new Date().getFullYear()-18)
<DatePicker
selected = { this.state.dob }
onChange = { this.dateChange }
className = "form-control"
maxDate = { ageRestriction }
/>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1