Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2914 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > JavaScript > Restrict some special characters from the textbox ...
Blessybaby

Restrict some special characters from the textbox

 Code Snippet posted by: Blessybaby | Posted on: 6/1/2009 | Category: JavaScript Codes | Views: 18132 | Status: [Member] | Alert Moderator   


function RestrictChar()
{
get the keycode when the user pressed any key in application
var exp = String.fromCharCode(window.event.keyCode)
//Below line will have the special characters that is not allowed you can add if you want more for some characters you need to add escape sequence
var r = new RegExp("[-_,/'().0-9a-zA-Z \r]", "g");
if (exp.match(r) == null)
{
window.event.keyCode = 0
return false;
}
}

in code behind we need to add below code for calling this function
txtuser.Attributes.Add("onkeypress", "javascript:return RestrictChar()");
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 6:38:32 PM