How do I trim left and right with jQuery?

Michael Sterling
Michael Sterling used Ask the Experts™
on
I need to trim a known amount of characters from an input box value (both left and right sides) using jQuery. What is the easiest way to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
just simply use substring
http://www.w3schools.com/jsref/jsref_substring.asp

var value = $("#textbox1").val();

value = value.substring(2); //removes first two characters
value = value.substring (0, value.length - 2 ); //remove last two characters

$("#textbox1").val(value);



Michael SterlingWeb Applications Developer

Author

Commented:
thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial