Tuesday, June 16, 2009

Removing white spaces entered in TextArea tag of HTML page



White spaces entered in Textarea of HTML page will be considered as Characters even when no other characters are entered.

These white spaces will then be inserted into database table unnecessarily.

So, to avoid this issue the below Javascript code can be used.

It will clear the whitespaces in the Textarea.



var str=document.getElementById(“category_name”).value;
var pattern_white_space=/^\s{1,4}/g;
var pattern_any_characters=/\w+/g;

if(str.match(pattern_white_space)&&!str.match(pattern_any_characters))
{
document.getElementById(“category_name”).value="";
}


More Articles...

1 comment:

Anonymous said...

This works fine! It removes all white spaces and carriage returns from a string and returns an empty string. It works on the assumption that the input string contaings no letters, numbers, commas, etc.



Thanks for visiting our blog


twitterrss facebook linkedin YouTube subscribe


Subscribe via email

Enter your email address: