65005262

Date: 2020-11-25 13:09:08
Score: 7.5
Natty:
Report link

How can I validate date with pattern if the user type it manually? My problem is, the typed date for example 11/24/2017 is always invalid.

The date value is: "Fri Nov 24 2017 00:00:00 GMT+0100 (Central Europe Standard Time)"

I using the following way:

<p-calendar id="dateOfDOB" [(ngModel)]="DOB" [showIcon]="true" [monthNavigator]="true" [yearNavigator]="true" yearRange="1900:2200" class="col-xs-12" [showOnFocus]="false" name="dateOfService" mask="99/99/9999" placeholder="mm/dd/yyyy" slotChar="mm/dd/yyyy" (ngModelChange)="onNgModelChangeDOB($event)" required="true" pattern="^((0?[1-9]|1[012])- /.- /.?[0-9]{2})*$" #dateOfDOB="ngModel">

Date of DOB is required. Date of DOB is invalid.

If I using dateFormat="mm/dd/yyyy" it duplicate the year in the field when I typed 11/24/2017 in this case the content of the field changed to 11/24/20172017. (why?)

What do you think about it, What I missed? What is the cause of this behavior?

Thank you in advance.

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (1.5): How can I
  • Blacklisted phrase (0.5): why?
  • RegEx Blacklisted phrase (3): Thank you in advance
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How can I
  • Low reputation (1):
Posted by: Ali Ashraf