Kinkis
Kinkis

Reputation: 31

Can I set <p:inputMask> (Primefaces) a mask to write none, one, two or three characters?

I know this mask: 99-999-9

I need to edit it a little bit, that I can type this:

Examples:

34-721-4

2-216-8

-12-5

2--5

1-13-7

I hope that you'll understand what I mean.

0-2 numbers '-' 0-3 numbers '-' 1 number(required)

Any ideas?

Upvotes: 3

Views: 4319

Answers (2)

Matteo Carminati
Matteo Carminati

Reputation: 11

We can define custom mask definitions as documented here http://digitalbush.com/projects/masked-input-plugin/ that is the jquery plugin used by primefaces inputMask.

just put something like that:

<script>
    $(document).ready(
        function() {
          $.mask.definitions['h'] = "[A-Fa-f0-9]";
        }
    );
</script>

somewhere in your xhtml file

Upvotes: 0

Youans
Youans

Reputation: 5061

According to this pdf page 15 and primefaces showcase example phoneWithExt

9 Permits only a number to be entered there.

a Permits only a letter (upper or lower case) to be entered there.

* Permits a letter or a number to be entered there.

? Indicates that everything following is optional

So this could do your job:

?99-?999-9

Upvotes: 6

Related Questions