0

I'm using NitroPDF to make custom forms and I have a problem....

Although NitroPDF allow me to format numbers using Arbitraty Mask, it only allow to use one custom pattern. But in my country, landline numbers have less numbers than cellphone numbers.

For example:

Landline: (99) 9999-9999
Cellphone: (99) 99999-9999

How could I let NitroPDF identify and apply mask based on field size, using javascript?

I don't know if this Arbitraty Mask allow me to do something like:

(99) 9999-9999 or (99) 99999-9999

Can someone help me? :)

Diego
  • 145
  • 4
  • 14

1 Answers1

0

Could you just specify the amount of digits you want with a limiting range?

(\(\d{2}\) \d{4,5}-\d{4})

So this looks for exactly two digits inside of parenthesis, followed by a space. Then it checks for either four or five digits. Finally, it looks for a dash followed by exactly four more digits.

Here is a demo

Quixrick
  • 3,190
  • 1
  • 14
  • 17
  • How do I make this work in PDF format? Pasting this in Custom Script and typing some numbers in the field do not get it formatted. – Diego Jun 10 '16 at 19:09
  • Sorry, I do not know. I was responding based on the "Regex" keyword, but I have never used NitroPDF. Is it just straight JavaScript? If so, you can try using the `test` method. It's basically something like this: `var patt = /Hello/g; var result = patt.test(str);` [Click here for more info](http://www.w3schools.com/jsref/jsref_regexp_test.asp) – Quixrick Jun 10 '16 at 19:23
  • This test code didn't work. I have no idea how to get this working because their docs do not share this info. But I have tested the code from this link and it worked (but in a different menu): http://support.nitropdf.com/entries/21780823-Javascript-Example-Subtraction-using-form-fields – Diego Jun 10 '16 at 19:45
  • Okay, so I did some searching around this site and found a good post that will probably answer your question. But first, I looked over the example you sent over and saw how you should be querying the field to get it as a variable. It should be something like this: `var phone_field = getField("PHONE_FIELD_GOES_HERE").value;` Then, take the example from [this guy's post](http://stackoverflow.com/questions/17651207/mask-us-phone-number-string-with-javascript) to kick it on in the drive. I reckon that either one of the first two answers should work for you. – Quixrick Jun 10 '16 at 21:02