Search the blog

If you’re validating an email address a space at the beginning and/or end of the input could cause the email to fail validation even though it looks okay to the user; this can happen if the email is pasted in. This simple bit of JavaScript will prevent that happening.

<input type="text" oninput="this.value = this.value.trim();" value="" />
Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.