Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript tab character removal

I need to remove tab characters within text inputted into particular fields of a web interface. The problem seems to be that when this happens the resulting text now contains spaces where the tabs were.

I tried using the regex : vVal = vVal.replace(/(\s+)/, ""); but using the example input 11111[tab], the value becomes 11111[space].

I dont know how this could be..

like image 332
user1769667 Avatar asked Nov 18 '13 20:11

user1769667


People also ask

How do I remove a tab character from a string?

You can remove any character/string from a string by using the Replace function. This allows you to specify the string you want to replace, and the value you want to replace it with. When you want to "remove" you simple use an empty string as the replace value.

How to remove whitespaces in js?

trim() The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string.

How to remove space with RegEx JavaScript?

Use JavaScript's string. replace() method with a regular expression to remove extra spaces. The dedicated RegEx to match any whitespace character is \s .


1 Answers

\s matches any whitespace that includes space also.

For tab try \t with global switch:

vVal = vVal.replace(/\t+/g, "");
like image 177
anubhava Avatar answered Sep 30 '22 14:09

anubhava