1

I have a plunkr here. How can I get the Submit button to be disabled till the dob is in mm/dd/yyyy pattern?

https://plnkr.co/edit/GtPDxw?p=preview

Here's the form

 <form [formGroup]="flashyForm">
    <input formControlName="dob" pattern="^\d{2}\/\d{2}\/\d{4}$"  placeholder="Date of Birth">
  <button type="submit" [disabled]="!flashyForm.valid">Submit</button>
</form>
1
  • I am not have it working yet, but you should put the pattern on the input (i am just checking it now with required) and i also think you are missing flashyForm.form.valid Commented Jul 19, 2016 at 15:50

2 Answers 2

1

You can try pattern="^(0[1-9]|1[0-2])/(0[1-9]|1[0-2])/([0-9]{4})$". Customize year as per your need.

Sign up to request clarification or add additional context in comments.

Comments

0

Pattern needs to be a string like

pattern="\d{2}\/\d{2}\/\d{4}"

^ and $ are added automatically. I don't remember if \ need to be escaped as \\, but I guess so.

See also https://github.com/angular/angular/issues/10150

3 Comments

It also needs to be on the input tag, I guess.
You're right. Didn't even see that :D That has to be a copy-past error or something.
@user6123723 have you tried it? Any different behavior or errors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.