Last active
December 23, 2015 02:39
-
-
Save frayhan32/6568660 to your computer and use it in GitHub Desktop.
Trim Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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