jQuery provide Trim method to remove spaces from start and end of a string
Syntax:
$.trim(string)
Here’s is a solution
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Remove Spaces from a start and end of a string using jQuery</title>
<script src="http://code.jquery.com/jquery-1.4.3.min.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function () {
$("#<%=Button1.ClientID %>").click(function (e) {
alert("'" + $.trim($("#<%=TextBox1.ClientID %>").val()) + "'");
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
FullName:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Click" />
</div>
</form>
</body>
</html>
Output

Download
Trim.zip (914.00 bytes)
Live Demo