Using jQuery $.trim() function you can remove whitespaces, newline and tabs which are sometime observed by user at the beginning or at the end of a textbox while entering text in textbox. In this article I will show you how to use this function to remove white spaces in textboxes in your HTML or ASP.NET Pages using jQuery coding.
Example
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery Example</title>
<script type="text/javascript"
src="jquery.js">
</script>
<script type="text/javascript">
$(function () {
$('input').blur(function () {
$(this).val(
$.trim($(this).val())
);
});
});
</script>
</head>
<body>
<input id="Text1" type="text" /><br /><br />
<input id="Text2" type="text" />
<body style="font-family: Verdana; font-size: small">
<strong>UserId or Email</strong>
<input id="Text1" type="text" /><br /><br />
<strong>Password</strong>
<input id="Text2" type="text" />
</body>
</html>
Here you observe white space at the beginning of both strings.

When you enters some text in the textbox with some white space, then the textbox value is fetched using $(this).val() and passed to the $.trim() function on the textbox blur event, and removes the white spaces at the beginning or end of the string.
Textboxes after removing white space