This is in Adobe campaign classic.

type="text" maxlength="10" pattern="[0-9]{10}"

It is allowing only 10 digits, but accepting - and . I want the user to enter only 10 not less or more and accept only digits. Please help.

2

There are 2 best solutions below

0
Hao Wu On

What you could do is to replace non-numeric characters(\D) after user input:

[...document.querySelectorAll('input[type="tel"]')].forEach(i =>
  i.addEventListener('input', () => i.value = i.value.replace(/\D/g, ''))
);
<input type="tel" maxlength="10" pattern="\d{10}" />

0
Adrian Sanchez On

You can always sanitize the input using a javascript piece of code. But as you are asking for a validation, simply use a numeric HTML input with max and min attributes.

E.g.

<input type="number" min="1000000000" max="9999999999">