How to limit the characters of the phone number

I want to prevent customers from placing more than X number of characters nor X less number of characters to avoid mistyped contact numbers

2 Likes

It might be possible with some Javascript, but I do not think it’s necessary, as we are working on a solution to make sure Phone numbers are valid before submitting the order. It might take sometime to be rolled out but will be worth the wait.

1 Like

I want to prevent customers from placing more than X number of characters nor X less number of characters to avoid mistyped contact numbers

Any news about the native phone number validation?

Please help us to how to set the limit of the phone number

Hi @Devesh_Kumar_Rai, @idelasotta, @Leonardo_Pedraza , @Camilo_Useche

I believe the above question was answered here: Help with a JavaScript code to limit the characters of the phone number

Looking forward to any feedback or suggestions. :smile:

Another article that might be useful: Phone Number Field Validation and Limiting With Error message and Country Code Included

Hi!

I hope you’re doing well.

I have the code to make this work, I used to validate phone numbers from Colombia.

<script>
    document.addEventListener('DOMContentLoaded', function () {
    var submitButton = document.getElementById('submitButton');
    // Agregar el evento en la fase de captura
    submitButton.addEventListener('click', function(event) {
        var inputTelefono = document.getElementsByName('phone')[0];
        var telefono = inputTelefono.value;
        var patronTelefonoColombia = /^3\d{9}$/;

        if (!patronTelefonoColombia.test(telefono)) {
            alert('Por favor ingrese un número de teléfono válido en Colombia (10 dígitos y comienza con 3).');
            event.stopImmediatePropagation(); // Detiene la propagación del evento
        }
    }, true); // True indica que el evento se maneja en la fase de captura
});

</script>

The only thing you have to set up the id of the submit button to ‘submitButton’.

If you have any doubts, don’t hesitate to contact me.

Lucio Garcia
Tech Expert
https://ltmsoluciones.com/us
https://ltmsoftware.com
Our instagram account

2 Likes