Good morning, could you help me with a JavaScript code to limit the number of characters in the phone number box, to prevent the client from leaving wrong data, I tried the following code but it doesn’t work for me.
<script> function leo($fields) { $fields['data-name=celular'], ['name=celular'], ['maxlength'] = 10; return $fields; } </script>
Here is a proper code:
<script> const MAX_LENGTH = 10; // change 10 to any other number. document.querySelectorAll('input[name="phone"]').forEach(i=>{ i.setAttribute('maxlength',MAX_LENGTH); }) </script>
This code will only limit the input length to the MAX_LENGTH given, but won’t do any further validation on the number.
MAX_LENGTH
We are working on native phone number validation.
Any news about the native phone number validation?