JSFiddle - React, Tailwind, and code Playground

HTML

<div id="output">
	
</div>

JavaScript

var str = 'We are inviting you for s special business meeting on Tueday, at No 12, Fred street. for more information please call 02341123333';

var updateString = function(input_text){
	 //1. Find consecutive 11 numeric digits
	 var match = input_text.match(/\d{11}/);
	 //2. divide it into a string of 3s separated by space
	 var new_str = '';
	 for(var i=1;i<match[0].length+1;i++){
	 	 new_str = new_str + match[0][i-1];
	   if(i>1 && i%3 == 0)
		    new_str = new_str + ' ';
	 }
	 //3. Replace old match no. with the new one
	 console.log(match)
   if (match [0] != '') 
   var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
            if (confirm("Message contains numeric characters which might make the message not delivered to some networks. Do you want us to reformat the message ?. This might increase the numbers of pages of the message and the cost?")) {
                confirm_value.value = "Yes";
                  
   
	 input_text = input_text.replace(match[0],new_str)
	 
	 document.getElementById('output').innerHTML = input_text;
   format (data);
            } else {
                confirm_value.value = "No";
            }
          document.getElementById('output').innerHTML = input_text;

   
}

updateString(str);