Reputation: 45
I have to check dynamically if the value written inside a textbox like:
<asp:TextBox ID="id" name="id" type="text"
size="50" Style="height: 22px; text-align: left;"
MaxLength="100" runat="server" />
have a length equal to 10 characters.
I want to show to the user an error alert like a balloon o a little sign near the box.
Upvotes: 0
Views: 69
Reputation: 1305
use Range Validators and specify Min and Max range
<asp:RangeValidator ControlToValidate="id" MinimumValue="10" MaximumValue="100" Type="Integer" EnableClientScript="false" Text="must be between 10 and 100!" runat="server" />
or else you can use jquery:
$('#ID').blur(function () {
var textval = ('#ID').val()
if(textval.length==4)
{
//Code to display enter code here your custom popup
}
});
Upvotes: 0
Reputation: 4559
You can use RegularExpressionValidator
for this. Put this code next to your TextBox
:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ErrorMessage="ID must be 10 characters long"
ControlToValidate="id" ValidationExpression=".{10}">
</asp:RegularExpressionValidator>
Upvotes: 1