1
I have a form in my application where the user can edit various data, including his date of birth. In the edit date field I am using this input:
<div class="col-md-6">
<label for="name">Data Nascimento</label>
<input
type="text"
formControlName="dataNascimento"
class="form-control"
id="name"
mask="{{maskDtNascimento}}"
[dropSpecialCharacters]="false"
placeholder="00/00/0000"
[readOnly]="justRead"
required
/>
</div>
The variable maskDtNascimento
is the following:
maskDtNascimento = '00/00/0000';
The problem is that in this way this input allows me to put dates in a wrong format, like this:
I’m using Angular 10 and ngx-Mask on this project. My question is: how to make this input not allow the user to enter invalid dates and still display the formatted value correctly?
The Mask does not do data validations, just format. For this you will have to create a function that takes the data and checks if the values are valid. Now I think it’s silly to waste time with this, if it’s an input and you want to get a date, I would use a simple date input!
– LeAndrade