0

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?

1 Answer 1

1
^\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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.