Javascript examples for String Operation:String Replace
Replace double period to single and if 4 or more replace to three with String replace and regex
<html> <head> <title>SO - 17271625</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){// w ww . j a v a 2 s . c om var fieldval = 'testing.. with ... and more .... and .........'; fieldval = fieldval.replace( /\.{2,}/g, function(val){ return val.length == 2 ? '.' : '...'; } ); console.log(fieldval) } </script> </head> <body> </body> </html>