Stack with Input Mask Phone number

I'm using input mask of RobinHerbots, and my problem here that jquery find any "9" is a number from 0-9, but i need it to be a real "9".

My country cellphone number: (09x) xxx-xxxx OR (012x) xxx-xxxx

my code:

$("#MainContent_txtSaveDIENTHOAI_NV").inputmask({
            mask: ["(099)-999-9999", "(0129)-999-9999"],
            clearIncomplete: true
        });

so, when i type "09" first, it should move to case 1; and type "01", it should be case 2. However, this js finds "01" or "09" is the same because "9" is "0-9".

Upvotes: 1

Views: 1602

Answers (3)

ravina vala
ravina vala

Reputation: 129

You need this js to implement input mask

https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js

Example with input field and jQuery

<input id="phn-number" class="ant-input" type="text" placeholder="(XXX) XXX-XXXX" data-inputmask-mask="(999) 999-9999">


jQuery( '#phn-number[data-inputmask-mask]' ).inputmask();

Upvotes: 0

ok, here my answer, it's worked !

$("#MainContent_txtSaveDIENTHOAI_NV").inputmask({
            mask: ["(0*9)-999-9999", "(0129)-999-9999"],
            greedy: false,
            definitions: {
                '*': {
                    validator: "9",
                    cardinality: 1
                }
            },
            clearIncomplete: true
        });

Upvotes: 2

Ajmal Ismail
Ajmal Ismail

Reputation: 111

I am not familiar with input-mask library but you might want to use this regex instead.

0(12|9)\d-\d{3}-\d{4}

Hope it helps.

Upvotes: 0

Related Questions