-1

The question is as :

  • The Telephone input field type should be 'tel',
  • The placeholder text should be Pattern: 234-567-8910
  • The pattern to restrict the entry and it should be a mandatory (required) field
  • Pattern should be of the type [ Pattern: 234-567-8910].
  • Element name should be: telephone.

My code is

<input type="tel" name="telephone" id="telephone" required placeholder="Pattern: 234-567-8910" pattern="">

What to write in the attribute pattern ?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

2 Answers2

0

The pattern in an input would take a regular expression. Your requirement is to get a regex what would fit in the requirement [ Pattern: 234-567-8910].

The regex would be

 pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
nXn
  • 904
  • 6
  • 13
0

For those of you do not understand, pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}", its like you are telling that the user can enter 3 digits from 0-9, than again 3 digits [0-9], than finally 4 digits between 0-9.

But the question is, why can't we write [0-9]{10}??