Reputation: 1
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.
Upvotes: 0
Views: 165
Reputation: 171
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">
Upvotes: 1
Reputation: 20669
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}" />
Upvotes: 0