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

8
  • possible duplicate of Remove literals from input mask after form submit? Commented Jul 8, 2015 at 10:20
  • So basically you want to void doing that every single time? 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 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 ... 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.net/jvr0nqz2 Commented Jul 8, 2015 at 10:32

3 Answers 3

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/

Sign up to request clarification or add additional context in comments.

Comments

2
$('.phone-input-order-form').mask(); => "999999999"

Comments

-1

do something like

yourstring.replace("-", ""); 

1 Comment

It's not DRY There are many lines of code where I should add condition and put replace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.