Minimum 50 character required for textbox

Posted by Nietajay under ASP.NET on 10/22/2012 | Points: 10 | Views : 3184 | Status : [Member] | Replies : 6
hi all,

i am using this code
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function MultiLineTextLength(MinimumCount) {
TextBox = document.getElementById('txtMultiline');
if (TextBox.value.length < 0)
{
alert("Please enter the value in textbox");
}
else if (TextBox.value.length < MinimumCount) {
alert("minimum " + MinimumCount + "character required in the textbox");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtMultiline" runat="server" onchange="MultiLineTextLength(50);"
TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>

but its validating only once if i hit button again its not validating ..

http://www.questionsofinterview.com

Ajay Kumar
Web developer



Responses

Posted by: Jayakumars on: 10/23/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try to onblur event.

Mark as Answer if its helpful to you

Nietajay, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.Net on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down

try below code
<asp:TextBox ID="TextBox1" runat="server"  />

<asp:RegularExpressionValidator ID="regExTextBox1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Minimum 10 characters"
ValidationExpression=".{10}.*" />


gowthaman8870226416

Nietajay, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 10/23/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
write this code on your page

<script language="javascript" type="text/javascript">
function MultiLineTextLength(MinimumCount) {
TextBox = document.getElementById('txtMultiline');
if (TextBox.value.length < 1) {
alert("Please enter the value in textbox");
return false;
}
else if (TextBox.value.length < MinimumCount) {
alert("minimum " + MinimumCount + " character required in the textbox");
return false;
}
return true;
}
</script>


<asp:TextBox ID="txtMultiline" runat="server" onblur="return MultiLineTextLength(50);"
TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="return MultiLineTextLength(50);" />


Nietajay, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Seng2hs on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
<script>
function CheckLength(ControlValue) {
var password = document.getElementById(ControlValue).value;
if (password.length < 50)
alert('should have miniumum 50 chars');
}
</script>

<asp:TextBox ID="txtMultiline" runat="server" onblur="CheckLength('txtpassword')"
TextMode="MultiLine"></asp:TextBox>

Use onBlur to do validation

Nietajay, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 10/23/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Nietajay

Please Mark As Answer if post will helps you.

Nietajay, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
try to use regular expresssion for such condition and use onBlur event
here is re:
/^.{50,}$/

Nietajay, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response