1
0
-1

Hi, we need to detect character entry on each keystroke for clean data entry validation.

On Blur, I can do the following which auto-corrects to the valid phone number format:

    var x = data.phone1.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
    data.phone1 = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');

But, it would be better to have the formatting while typing.

 

What is the equivalent of this type of addEventListener in Maestro:

document.getElementById('phone').addEventListener('input', function (e) {
  var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/); 
 e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : ''); 
 
});

 

Thanks,

Trevor

 

    CommentAdd your comment...