Mike
Mike

Reputation: 55

Html form field - remove spaces Javascript

Is there a way to remove any spaces in a form field, the "onblur" solutions when i have googled it are not working for me. Is it anything to do with browser compatability? Im using IE10

Upvotes: 0

Views: 2205

Answers (3)

Rubén Amaro
Rubén Amaro

Reputation: 64

you can use this function to remove spaces, try it:

function removeSpaces(ch)
{
   ch = ch.replace(/\ /g,"");
   return ch;
 }

Upvotes: 1

Gaucho_9
Gaucho_9

Reputation: 265

You can use via jquery trim function.

http://api.jquery.com/jquery.trim/

Upvotes: 0

Samp
Samp

Reputation: 385

Put this between your head tags:

<script language="javascript" type="text/javascript">
function removeSpaces(string) {
return string.split(' ').join('');
}
</script>

And this in your input tag:

onblur="this.value=removeSpaces(this.value);"

Upvotes: 3

Related Questions