4

I am using masked-input-plugin but it changes value and field becomes invalid ...

in my js

$phoneInput.mask('99-99-99-999');

and later in browser console

('.phone-input-order-form').val()
"99-99-99-999"

Is there any way to get from val "999999999" while it masked ?

I am thinking to extend jQuery val but maybe you know better way? maybe without this plugin? :D

madzohan
  • 11,488
  • 9
  • 40
  • 67
  • possible duplicate of [Remove literals from input mask after form submit?](http://stackoverflow.com/questions/7854651/remove-literals-from-input-mask-after-form-submit) – stevenw00 Jul 08 '15 at 10:20
  • So basically you want to void doing that every single time? – briosheje Jul 08 '15 at 10:21
  • seems I asked clearly - 1) or extend `val`; 2) or somehow show mask without affect to inputs value – madzohan Jul 08 '15 at 10:23
  • @stevenw00 nope, It's not DRY There are many lines of code where I should add condition and put unmask or replace or whatever ... – madzohan Jul 08 '15 at 10:28
  • what about a **newer** prototype so that you won't need to extend .val()? do you have to replace that .val() so many times? something like that? http://jsfiddle.net/jvr0nqz2/ – briosheje Jul 08 '15 at 10:32
  • @briosheje I have took idea from this answer http://stackoverflow.com/a/5007327/3033586 – madzohan Jul 08 '15 at 10:36
  • @madzohan: Not sure, I feel that it is easier to create a new prototype, but maybe it's just me. – briosheje Jul 08 '15 at 10:40
  • If you change `val` things will probably stops working, because inside masked-input-plugin it also uses `val`, so it creates some kind of circular dependencies. – alan0xd7 Jul 08 '15 at 10:45

3 Answers3

3

Overriding jQuery's val() function might cause unexpected issues with other scripts. Maybe try something like this:

$.fn.maskVal = function () {
    return $(this).mask();
};

Demo: http://jsfiddle.net/alan0xd7/w4s0v7y3/

alan0xd7
  • 1,831
  • 1
  • 15
  • 19
2
$('.phone-input-order-form').mask(); => "999999999"
Evgeny Samsonov
  • 2,730
  • 4
  • 19
  • 28
-1

do something like

yourstring.replace("-", ""); 
jay temp
  • 1,207
  • 12
  • 11