Replace space character with slash surrounded by spaces " / " - Javascript String Operation

Javascript examples for String Operation:String Replace

Description

Replace space character with slash surrounded by spaces " / "

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-compat-git.js"></script> 
  <script type="text/javascript">
    $(window).on('load', function() {
$('#field').bind('keyup', function() {
    var myStr = $(this).val()/* ww w  . j a  v a 2 s  . c om*/
    myStr=myStr.replace(/\s+$/g, ' / ');
    $('#field').val(myStr);
});
    });

      </script> 
 </head> 
 <body> 
  <input type="text" id="field">  
 </body>
</html>

Related Tutorials