Skip to content

Instantly share code, notes, and snippets.

@jerinisready
Created May 7, 2018 06:04
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 jerinisready/e38107f54ec958c7d5c76cc31fbe00c4 to your computer and use it in GitHub Desktop.
Save jerinisready/e38107f54ec958c7d5c76cc31fbe00c4 to your computer and use it in GitHub Desktop.
trim any spaces at the start of the text box and trim any spaces at the end of the textbox.
<script>
function trim(el){
el.value = el.value.
replace (/(^\s*)|(\s*$)/gi, ""). // removes leading and trailing spaces
replace (/[ ]{2,}/gi," "). // replaces multiple spaces with one space
replace (/\n +/,"\n"); // Removes spaces after newlines
return true;
}
</script>
<input type="text" name="email" id="_email" pattern=".{3,}@.{3,}\..{2,5}" onchange="return trim(this)" required="required" class="input input_email" placeholder="Email Address *">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment