<input type="text" onBlur="replaceSpace(this)" /> <script type="text/javascript"> function replaceSpace(obj) { obj.value = obj.value.replace(/\s/gi, '') } </script>