Created
February 9, 2010 09:31
-
-
Save randika/299049 to your computer and use it in GitHub Desktop.
Javascript trim with Regular Expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
//Javascript trim() example | |
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }; | |
//Usage: | |
var str = " foo bar "; | |
alert("Original string: '" + str + "'"); | |
str = str.trim(); | |
alert("Trimmed string: '" + str + "'"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment