Remove spaces at the beginning of the text box

Hi All,

I am using the following code to remove white spaces at the beginning of txt box.if i change textbox name it doesnot work.

Please Someone help.

<script>
//Javascript
function white_space(field)
{
     field.value = (field.value).replace(/^\\s*/g,'');
}
</script>

//example HTML
<form action="" method="get" name="test_form">
     <input type="text"   name="text"  onKeyPress="white_space(text)"  />
     <input type="button" name="button" value="button" />
</form>
function white_space(field)
{
     field.value = field.value.replace(/^\\s+/, "");
}
<form action="" method="get">
  <div>
     <input type="text" name="text"  onkeypress="white_space(this)">
     <input type="button" name="button" value="button">
  </div>
</form>