Return to Solutions Overview <-

Format Webflow Number Inputs Properly

Sure, here's the modified formatNumber function that joins the groups with a comma instead of a space: javascript Copy code function formatNumber(input) { // Remove all non-digit characters from the input let digitsOnly = input.replace(/\D/g, ''); // Split the string into groups of three digits each, starting from the end let groups = digitsOnly.match(/.{1,3}(?=(.{3})*$)/g); // Join the groups with a comma between them and return the result let result = groups ? groups.join(',') : ''; // Make sure the first digit is not 0 if (result.startsWith('0')) { result = result.slice(1); } return result; } This function splits the string into groups of three digits from the start of the string, joins the groups with a comma between them, and then removes any leading zeros. With this function, the formatting should work as follows: rust Copy code 1 -> 1 10 -> 10 100 -> 100 1000 -> 1,000 10000 -> 10,000 100000 -> 100,000 1000000 -> 1,000,000 10000000 -> 10,000,000 001 -> 1 010 -> 10 00010 -> 10 I hope that helps! Let me know if you have any further questions.

(Still under development as of March 15th 2023)

Nice little conversation I had with ChatGPT:



Sure, here's the modified formatNumber function that joins the groups with a comma instead of a space:

javascriptCopy code

$('input').on('input', function() {
    $(this).val( formatNumber($(this).val()) )
})


function formatNumber(input) {
  // Remove all non-digit characters from the input
  let digitsOnly = input.replace(/\D/g, '');

  // Split the string into groups of three digits each, starting from the end
  let groups = digitsOnly.match(/.{1,3}(?=(.{3})*$)/g);

  // Join the groups with a comma between them and return the result
  let result = groups ? groups.join(',') : '';
  
  // Make sure the first digit is not 0
  if (result.startsWith('0')) {
    result = result.slice(1);
  }

  return result;
}


This function splits the string into groups of three digits from the start of the string, joins the groups with a comma between them, and then removes any leading zeros.

With this function, the formatting should work as follows:

rustCopy code

1        -> 1
10       -> 10
100      -> 100
1000     -> 1,000
10000    -> 10,000
100000   -> 100,000
1000000  -> 1,000,000
10000000 -> 10,000,000
001      -> 1
010      -> 10
00010    -> 10

I hope that helps! Let me know if you have any further questions.

FAQs

You still have an open question about BMG.studio and how we operate. Chances are good that you will find what you are looking for here:

Why does this FAQ exist?

Well. As of Wednesday, March 15th 2023, I think this component looks really cool.

Can I clone this FAQ component?

Yes. Yes you can. You can do so -> here <-

Still have questions?

It's okay to reach out. Use either email or our calendar tool