0

I created a function to get the length of my input value and applying a different replace (a mask) for each one, but it's not working. Check it out:

function mask_vat(inputID) {
    var mystr = document.getElementById(inputID).value;
    var str_length = mystr.length;
    var pattern, replacement;
        switch(str_length) {
            case 14:
                pattern = '/^(\d{3}).\d{3}.\d{3}-(\d{2})$/';
                replacement = '$1.XXX.XXX-$2';
                break;
            case 18:
                pattern = '/.\d{3}.\d{3}\//';
                replacement = '.xxx.xxx/';
                break;
        }
    mystr.replace(pattern, replacement);
}

what's wrong in the function??

1

1 Answer 1

1

In Regex . represents all character except new line. To use a . use \..

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

Comments

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.