Javascript-html's textarea, how to remove the blanks when submitting?

Source: Internet
Author: User
Keywords Html php javascript
HTML textarea, how to remove the end-to-end space when submitting?
The front-end JS and back-end PHP should all be able to remove it?
How do you do it?
It is necessary to note that only the first and last spaces of the entire textarea are removed, if there is a newline in the middle of the text, or there are spaces, regardless of it.

Reply content:

HTML textarea, how to remove the end-to-end space when submitting?
The front-end JS and back-end PHP should all be able to remove it?
How do you do it?
It is necessary to note that only the first and last spaces of the entire textarea are removed, if there is a newline in the middle of the text, or there are spaces, regardless of it.

First of all, a lot of people upstairs said Trim ().

So, why do textarea have spaces?

Don't do this:

内容。

To do this:

内容

Using the String.Trim () method of the string

Trim ()

All can, in JS, everything is the object, the string is also, so you can use the string. Trim ()
Trim in PHP is a function that uses trim (string)

You can replace it with a regular. But with trim convenience

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.