Opened 14 years ago
Closed 13 years ago
#4848 closed enhancement (wontfix)
trim method doesn't trim all white-space
Reported by: | dotnetCarpenter | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | core | Version: | 1.3.2 |
Keywords: | trim, patch, regex | Cc: | |
Blocked by: | Blocking: |
Description
The trim method only removes white-space from the beginning and end of a string. I often need to remove all space, e.i. a telephone number ect. Therefore I suggest a second optional boolean argument called 'all'. If 'all' is true, all white-space is removed.
Test Case var withSpace = $.trim(' 432 334 532 '); var noSpace = $.trim(' 432 334 532 ', true);
Patch /
- Uses a regular expression to remove whitespace from the given string.
- @param {String} text The string to trim.
- @param {Boolean} [all] True to remove all white-space from the text.
- @return {String} */
trim: function(text, all) {
return all===true ? (text "").replace( /\s+/g, "") : (text "").replace( /\s+|\s+$/g, "" );
}
Change History (4)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Test Case
console.log($.trim(' 432 334 532 ')); console.log($.trim(' 432 334 532 ', true));
comment:3 Changed 14 years ago by
I don't think you understand the meaning of "trim". I would just override trim with your function. I don't think this should be a part of jQuery.
comment:4 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This isn't something that we're going to be landing - should make for a fine plugin, though.
Patch code without wiki formatting: