.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Not Allowed Special Characters and Space in TextBox.

Posted By:Shashi Ray       Posted Date: March 25, 2009    Points: 10    Category: ADO.NET    URL:   


In Aspx Code

<script type="text/javascript">


function NotAllow()




alert ("Please enter more than 4 characters")





alert ("Please enter less than 16 characters")


var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";


 for (var i = 0; i < document.form1.TextBox1.value.length; i++)


         if (iChars.indexOf(document.form1.TextBox1.value.charAt(i)) != -1)


         alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");

         return false;







In Aspx.cs Code

Button1.Attributes.Add("onclick", "return NotAllow();");



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend