0

We are trying to mask the input field as (999) 999-9999 x9999 but I need to show x symbol if user enters 14 characters I need to make visible the x symbol.We got output as expected.

Is there any problem in this script or any better way to do this ?

JS:

$(document).delegate('#BPhone', 'keyup', function(e) {
    var Textlength = $(this).val();
    console.log(Textlength.length);

    if (Textlength.length >= 14)
        $("#BPhone").mask("(999) 999-9999 x9999");
    else
        $("#BPhone").mask("(999) 999-9999");
});

HTML:

<input id="BPhone"  class="" type="tel"  value="" maxlength="20"  placeholder="">
Iván Rodríguez Torres
  • 3,963
  • 3
  • 29
  • 43
CodeMan
  • 1,841
  • 5
  • 24
  • 44
  • try [digitalbush](http://digitalbush.com/projects/masked-input-plugin/) – guradio Apr 28 '16 at 09:17
  • 1
    as Liam suggests, i post it as a comment: I think this is a good solution if it works as expected If i can give an advide, don't overthink little pieces of code like this one. It is short, it works, it doesn't need enough calculation time to be worthy of consideration: even thought a better solution actually exists, probably the improvement is not worthy the time you need to reach it. – gbalduzzi Apr 28 '16 at 09:27

0 Answers0