<!DOCTYPE html> <html lang="fr" <head> <meta charset="utf-8"> <title>TEST</title> </head> <body> <input type="text" name="test" onkeyup="formatNumber(this)" > <script type="text/javascript"> function formatNumber(el){ console.log(" Ancienne valeur :" + el.value); el.value=el.value.replace(/(\d)(?=(?:\d{2})+(?:$))/g, '$1 ') console.log(" Nouvelle valeur :" + el.value); } </script> </body> </html>