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


Top 5 Contributors of the Month
abhays
satyapriyanayak
SP
Ashutosh Jha
ASPEvil

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()

{

if(document.form1.TextBox1.value.length<4)

{

alert ("Please enter more than 4 characters")

}

 

if(document.form1.TextBox1.value.length>16)

{

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;

         }

 }

}    

 

script>

 

In Aspx.cs Code

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

 



     

Further Readings:

Responses

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