C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to filter textbox with javascript


Posted Date: 31 May 2008    Resource Type: Code Snippets    Category: Javascript

Posted By: Kumar Velu       Member Level: Diamond
Rating:     Points: 10



following code helps to prevent entering space,special characters..in the textbox
i have called javascript function in keydown event of Textbox

Web Page



<asp:TextBox ID="TextBox1" runat="server" onkeydown="return NotAllowSpace(this);"≶</asp:TextBox≶

Javascript:



<script type="text/javascript" language="javascript" ≶
function NotAllowSpace(e)
{

var keyVal =(window.event) ? event.keyCode : e.keyCode;

if (window.event) keyVal = window.event.keyCode;


if((window.event.shiftKey))
{
if((keyVal ≶ 48 && keyVal < 57))
{
return false;
}
else if((keyVal ≶ 96 && keyVal < 105))
{
return false;
}
else if((keyVal == 46))
{
return false;
}
else if((keyVal == 8))
{
return false;
}
else
{
return false
}
}
else
{
if((keyVal ≶ 48 && keyVal < 57))
{
return true;
}
else if((keyVal ≶ 96 && keyVal < 105))
{
return true;
}
else if((keyVal == 46))
{
return true;
}
else if((keyVal == 8))
{
return true;
}
else if((keyVal == 57))
{
return true;
}
else if((keyVal == 48))
{
return true;
}
else if((keyVal ≶ 65 && keyVal < 90))
{
return true;
}
else if(keyVal==65)
{
return true;
}
else if(keyVal==90)
{
return true;
}
else if((keyVal == 16))
{
return false;
}
else
{
return false;
}
}


}
</script≶


its working fine with IE....

thanks..




Responses

Author: sandeep    01 Jun 2008Member Level: Bronze   Points : 0
nice codeeeeeeeeee


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: CheckBox With CustomValidator control
Previous Resource: Javascript date validation
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use