Use regex to filter text - Javascript String Operation

Javascript examples for String Operation:String Replace


Use regex to filter text

Demo Code

ResultView the demo in separate window

      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <textarea id="ta" name="ta" onkeyup="clean('ta')" onkeydown="clean('ta')"></textarea> 
      <script type="text/javascript">
    function clean(e) {/* w  ww . ja  v a  2s . com*/
        var textfield = document.getElementById(e);
        var regex = /[a-zA-Z]/gi;
        textfield.value = textfield.value.replace(regex, "");


Related Tutorials