Make sure that you have the correct regional setting for wherever you are as the phone automatically formats the numbers as per the correct format in most countries.
Settings > General > international > Region Format.
For example, here in Ireland the numbers automatically format as
(088) XXX XXXX or 1800 XX XX XX for free numbers etc it knows the correct format for every type of number. It should do the same for most other countries where iPhones are marketed too eg UK 07XX XXX XXX or 020 XXXX XXXX France 01 XX XX XX XX Spain 6XX XXX XXX US/Canada (212) XXX-XXXX and so on.
If you're storing numbers, you're best to include the international access codes as this avoids you having to edit numbers while abroad an they work normally while at home. This has been a feature of GSM phones since the system was introduced in the early 1990s
So for UK +44, Ireland +353, USA and Canada +1, Australia +61 and so on ....
The numbers should jump into the correct layout for each country's numbering system.
There are a few exceptions where numbering systems don't specify a layout with spaces, dashes, brackets and slashes where the number will just enter as a long string.
Also where numbers are stored in your phone without formatting it doesn't reformat them automatically. It only happens for new numbers stored on your iPhone.