Is there a way to format numbers with leading zeroes in a Writer Form?

I am trying to design a simple form in LibreOffice Writer so that several people can use it to make a record of the name, address etc. of their students. For various reasons they can’t use a central database for this and just want something they can fill in and print or email.

I was going to set up the phone number field as 5 2-digit fields (so it displays in the standard format for the locale) but if I use a numeric field it insists on dropping any leading zeroes. Is there any way to make a form field that only accepts numbers but will retain leading zeroes?


A Pattern field may be of help:

Refer to Base documentation → LibreOffice Base Guide. See Chapter #4 - Forms. Pattern field section.

There is a common misconception about phone “numbers”. They aren’t numbers but symbols written with digits and every digit is significant, even leading zeroes.

The best form element would be a text box in order to keep leading zeroes. However, a text box will not enforce the restriction to digits nor the fixed-length phone number format. Hence, you should use a Formatted Field element (icon looking like a $ sign). Once created, right-click on it and Control Properties. Scroll down to Formatting properties. Click on the ... button to access the format definitions.

In the simplest case, under Number category, enter as many 0 as a phone number has digits in your country and set the number of leading zeroes equal to this number.

If you want some “decoration” in the numbers, such as spaces or dashes, create your own format code in the User-defined category. For instance for a North-American number enter "("000") "000"-"0000.

Remember however this is only formatting of a number. A phone number may be very long (UIT standards say up to 15 digits) and this length may not be compatible with what can be understood as an integer within a floating-point number, compelling you to revert a string of characters.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.

Thank-you. I could not find a field called Pattern Field but I found Formatted Field, which does exactly what I need.

We do appreciate feedback and comment, but this site ergonomy reserves answers for solutions to problems. So, please, use the more link under your “non-answer” to repost as a comment. Thanks in advance because it otherwise confuses users looking for solutions.