Skip to content

Instantly share code, notes, and snippets.

@frayhan32
Last active December 23, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frayhan32/6568660 to your computer and use it in GitHub Desktop.
Save frayhan32/6568660 to your computer and use it in GitHub Desktop.
Trim Function
//Trim function i usually use this to dismiss space either in the front , back , or middle
//very useful when dealing with email input so no space is exist
/*this is alternative way , whether you want to use keypress validation that just allow number , character , space , an , backspace
its up to you*/
//**********************************//
//***********TRIM FUNCTION***********//
//**********************************//
function trim(str){
return str.replace(/^\s+/g,"").replace(/\s+/g,"")
}
/*test him*/
var a=' A B ';
alert(a.length);
alert(trim(a).length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment