Quick Search

Spacebar Check in TextBox Using Javascript

February 27th, 2010 by admin
Leave a reply »

 

Trim Function using java script.Validation for text box if there only space using java script.validation for space in text box using java script.

Solution:

Create A textbox with id txtname and a button id btntest and wite this function inside script tag.

function trim(string)
{
var a = string.replace(/^\s+/, ”);
return a.replace(/\s+$/, ”)
}
function TestTrim()
{

x = window.document.getElementById(“txtname”);
str=”Please Enter User Name”;
if (trim(x.value)==”")
{
alert(str);
x.select();
x.focus();
return false ;
}
}

And then call the function on c#(code behind page)
btntest.Attributes.Add(“onclick”, “return TestTrim();”);

Posted in Javascript

You can follow any responses to this entry through the RSS 2.0 Feed. You can leave a response , or trackback from your own site.

1 commentAdd your comment
  1. I just wanted to comment your blog and say that I really enjoyed reading your blog post here. It was very informative and I also digg the way you write! Keep it up and I’ll be back to read more soon mate

 

Leave a Reply

SEO Company India

search engine marketing company India that offers affordable seo services