Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Formatting French numbers

Community Expert ,
Feb 19, 2025 Feb 19, 2025

Hello

I have a specific request from a customer for which I can't find the solution either in this forum or in the documentation.

 

First of all, you need to know that in French, numbers are written with a comma to separate decimals, and with a space to separate thousands.
Example: 123 456,78

 

I could do without the space between the thousands, but I absolutely need the user to be able to enter a maximum of 6 digits, plus if necessary a comma and a maximum of 2 decimal places.

 

The problem with Acrobat's number format is that it allows to enter more than two digits after the decimal point, and then rounds them down to two.

It is therefore not usable in this particular case.

 

I know how to make a keystroke script that limits input to 6 digits with a space between the thousands, but I don't know how and I can't manage the comma and the limit for decimals.

 

I know how to do it in a Format or in a Validation script, but the customer wants the user to be restricted during input, so it doesn't work.
I absolutely need a keystroke script.

If this script could also handle the space between the thousands, it would be perfect, but that's not the most important thing.

 

Thank you for your help.


Acrobate du PDF, InDesigner et Photoshoptographe
TOPICS
JavaScript , PDF , PDF forms
197
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 19, 2025 Feb 19, 2025

See if this works (without a thousand separator):

 

if (!event.willCommit) {
 var selStart = event.selStart;
 var selEnd = event.selEnd;
    
 var newValue = (selStart === 0 && selEnd === event.value.length) 
  ? event.change
  : event.value.slice(0, selStart) + event.change + event.value.slice(selEnd);

  event.rc = /^(\d{0,6}(,\d{0,2})?)?$/.test(newValue);}

EDIT:
If you want manually input space, try with this:
/^(\d{0,3}(?:\s?\d{0,3})?(,\d{0,2})?)?$/

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2025 Feb 19, 2025

See if this works (without a thousand separator):

 

if (!event.willCommit) {
 var selStart = event.selStart;
 var selEnd = event.selEnd;
    
 var newValue = (selStart === 0 && selEnd === event.value.length) 
  ? event.change
  : event.value.slice(0, selStart) + event.change + event.value.slice(selEnd);

  event.rc = /^(\d{0,6}(,\d{0,2})?)?$/.test(newValue);}

EDIT:
If you want manually input space, try with this:
/^(\d{0,3}(?:\s?\d{0,3})?(,\d{0,2})?)?$/

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2025 Feb 19, 2025
LATEST

Thank you, thank you!

It works fine.

 

I suggest you add "The JavaScript & GREP Queen" to your signature.


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines