javascript - Angular directive to replace character from user input -


i want trim characters user input. want trim '%, *, ), ( ' if user give of character want show on search box in js want set model value without these restricted characters.

something like:

user input 'a&b'  want set in scope 'ab' 

this question(angular.js - controller function filter invalid chars input not delete chars until valid char entered) answers want without showing on user.
in advance.

use:

<script>  var user_input = "%this (is) string*";  var new_string = plainstring(user_input) alert(user_input);   function plainstring() {     var findit = [ '%', '*', ')', '('];     for(i=0; i<findit.length; i++) {         user_input = user_input.replace(findit[i],'');       }     return; }  </script> 

or can use

<script>  string.prototype.myreplace = function(find, replace) {     var str = this;     (var = 0; < find.length; i++) {         str = str.replace(find[i], replace);     }     return str; };  var user_input = '%this (is) string*'; var find = ["%", "(", ")", "*"]; user_input = user_input.myreplace(find, ""); alert(user_input);  </script>     

output:

this string 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -