In the html textarea, how do I remove spaces at the beginning and end when submitting? Can front-end js and backend php be removed? How can this problem be solved? It should be noted that only the first and last spaces of the entire textarea are removed. If a text contains a line break or a space in the middle, no matter it. In the html textarea, how do I remove spaces at the beginning and end when submitting?
Can front-end js and backend php be removed?
How can this problem be solved?
It should be noted that only the first and last spaces of the entire textarea are removed. If a text contains a line break or a space in the middle, no matter it.
Reply content:
In the html textarea, how do I remove spaces at the beginning and end when submitting?
Can front-end js and backend php be removed?
How can this problem be solved?
It should be noted that only the first and last spaces of the entire textarea are removed. If a text contains a line break or a space in the middle, no matter it.
First, many people on the upstairs say trim.
So why is there a space at the beginning and end of textarea ..
Do not:
Content.
To do this:
Content
Use the string. trim () method of the string
Trim ()
Yes. In js, everything is an object, and the string is the same, so you can use string. trim ()
Trim is a function in php and its usage is trim (string)
It can be replaced with a regular expression. However, trim is convenient.
Var re =/^ s + | s + $/g;
Var str = $ ('# textarea'). val ();
Var text = str. replace (re ,'');