SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jun 6, 2007, 19:36 #1
- Join Date
- Jul 2004
- Posts
- 43
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Javascript String doesn't have trim method ?
I was trying:
Code:<script> function testtrim(value) { alert(value.trim()); } testtrim("Alex "); </script>
how to simulate an trim function ?
thanks.
-
Jun 6, 2007, 20:18 #2
- Join Date
- Feb 2003
- Location
- Slave I
- Posts
- 23,424
- Mentioned
- 2 Post(s)
- Tagged
- 1 Thread(s)
Code:String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g,''); }
-
Jun 6, 2007, 20:49 #3
- Join Date
- Jul 2004
- Posts
- 43
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jun 7, 2007, 04:50 #4
- Join Date
- Jun 2003
- Location
- Malden, MA
- Posts
- 142
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes, as with any programming language you can define your own functions. The one below is actually from the prototype javascript library. If you use that library (just a bunch of prewritten functions to make your life easier), then you will get that function and many others.
Keith Rousseau
-
Jun 7, 2007, 06:44 #5
- Join Date
- Feb 2003
- Location
- Slave I
- Posts
- 23,424
- Mentioned
- 2 Post(s)
- Tagged
- 1 Thread(s)
Bookmarks