I am using masked-input-plugin but it changes value and field bees 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
I am using masked-input-plugin but it changes value and field bees 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
- possible duplicate of Remove literals from input mask after form submit? – stevenw00 Commented Jul 8, 2015 at 10:20
- So basically you want to void doing that every single time? – briosheje Commented Jul 8, 2015 at 10:21
-
seems I asked clearly - 1) or extend
val
; 2) or somehow show mask without affect to inputs value – madzohan Commented Jul 8, 2015 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 Commented Jul 8, 2015 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? jsfiddle/jvr0nqz2 – briosheje Commented Jul 8, 2015 at 10:32
3 Answers
Reset to default 3Overriding 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/alan0xd7/w4s0v7y3/
$('.phone-input-order-form').mask(); => "999999999"
do something like
yourstring.replace("-", "");