The use method of JS Trim,ltrim,rtrim function

Source: Internet
Author: User
Tags rtrim

Today to use JavaScript to remove a text box at the ends of the string space, began to think there is a Trim,ltrim,rtrim function (ASP has these three functions, confused), the results find half a day, did not find. Finally, we find a custom function that uses the same functionality as the regular implementation.
<script type= "Text/javascript" >
function Trim (str) {//Remove spaces at left and right ends
Return Str.replace (/(^\s*) | ( \s*$)/g, "");
}
function LTrim (str) {//delete left space
Return Str.replace (/(^\s*)/g, "");
}
function RTrim (str) {//Remove the right space
Return Str.replace (/(\s*$)/g, "");
}
</script>
How to use
<script>
function aaa ()
{
var S=document.getelementbyid ("text box ID"). value;
Alert (Trim (s));
}
</script>

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.