As soon as the user leaves the username text input, the value of the input is trimmed; removing leading and trailing spaces.
Case 1: Directly in the Tag
javascript syntax: this.value=this.value.replace(/(^\s*)|(\s*$)/g, "");
Code view
Username <input name="userName" type="text" id="userName" style="display:block;margin-top:5px;margin-bottom:5px;" onblur=' this.value=this.value.replace(/(^\s*)|(\s*$)/g, "") ; ' />
Case 2: with Reusable Javascript
Here we use javascript to access the username input field as a DOM object and apply the onblur attribute.
Code view
Username <input name="userName" type="text" id="userName" style="display:block;margin-top:5px;margin-bottom:5px;" onblur=' ' />
<script language="JavaScript" type="text/javascript">
function myObj(tagID){return document.getElementById(tagID) ; };
trim=function(){this.value=this.value.replace(/(^\s*)|(\s*$)/g, "");}
myObj("userName").onblur=trim
</script>