In javascript-html textarea, how do I remove spaces at the beginning and end of a request?

Source: Internet
Author: User
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 ,'');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.