Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have declare a column of type varchar(50) in back end. How to restrict user to enter only 50 characters in Textbox?
Posted
Updated 20-Jul-10 5:21am
v2
Comments
thatraja 20-Jul-10 11:25am    
Typo(s) was fixed in question.

Mate, It's a basic question, you should search in search engines before you posting basic questions. Set Maxlength="50" to that appropriate Textbox.
 
Share this answer
 
v3
Comments
satpal 2 23-Jul-10 5:06am    
question is not understood properly
There can be various ways to do it.

1. Setting MaxLength (already suggested above)
2. Use Javascript to track the characters filled based on onchange/onkeypress events
3. Use Regular Expression Validators to take care
4. Use Masked textboxes (option 2/3 is internally implemented)
 
Share this answer
 
Sandeep is correct.
there are various ways to do it.
if you want to validate your user input using javascript heres a basic function

JavaScript
<script type="text/javascript">

function validate() 
{ 
    if (document.getElementById('txt').value.length > 50) 
    { 
        alert("error message"); return false 
    }
}
</script>

XML
<input type="text" id="txt" />
<input button="submit" onclick="return validate();" />
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900