Reputation: 1357
My input field is
<input type="text"
class="form-control"
name="locphone"
[(ngModel)]="locmodel.locphone"
#locphone="ngModel"
[ngClass]="{ 'is-invalid': f2.submitted && locphone.invalid }"
required
locphone
pattern="^\s*(?:\+?\d{1,3})?[- (]*\d{3}(?:[- )]*\d{3})?[- ]*\d{4}(?: *[x/#]\d+)?\s*$" />
Phone number should be in phone number format 999-999-9999
Here how to change the pattern to support this format alone?
Upvotes: 0
Views: 6217
Reputation: 8868
^\d{3}-\d{3}-\d{4}$
valid:
123-456-7890
333-333-4444
invalid:
1234567890
123456789
123-4567-890
14157059247
test: https://www.regextester.com/94189
Upvotes: 1