Obtain the regular expression that uses JS to remove spaces from data sent from the server.

Source: Internet
Author: User

This morning till now, I have been engaged in a very stupid problem and have not found it.
If $ str = "";
$ Str = "$ str-$ sno ";

In this case, there will be a space in front of $ str. After js obtains this value, it must remove the space.

Remove the space function rstr = rstr. replace (/(^ \ s *) | (\ s * $)/g ,"");

In addition:

Remove the left space replace (/(^ \ s *)/g ,"");

Remove the right space replace (/(\ s * $)/g ,"");

In addition, if you perform step-by-step verification of the program flow, stop at the if. Make sure to output the two values in the if for comparison, or add # To the front to check whether there is space.

To sum up

1. space may be generated when a string is used for connection. When the string is split, it may be different from the original one. Therefore, you must remove the leading and trailing spaces.

2. When obtaining data from the server, JS must pay attention to the possibility of Space occurrence.

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.