The following RegEx formats given string to following output block pattern:
123 456 78 90 (= 3 digits 3 digits 2 digits 2 digits )
RegEx:
string.replace(/^(\d{3})(\d{3})(\d{2})(\d{2})$/g, '$1 $2 $3 $4');
This example only works, if given input string matches exact length of 10 digits.
How can I adjust the RegEx to work with every string length?
- 1234 --> 123 4
- 1234567 --> 123 456 7
- 123456789 --> 123 456 78 9
- 1234567890123 --> 123 456 78 90 12 3
Background: I want to format the input string of a form input field directly, when a user enters the number...