我有一个文本框..
我想根据下拉列表值验证它的值。
所以我使用RegularExpressionValidator
显示来自代码的消息..
但它没有工作PLZ,给我建议..
<asp:TextBox ID="tbnooflecture" runat="server" Width="119px" Height="33px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ForeColor="#6600FF"
runat="server" ValidationGroup="upper"
ControlToValidate="tbnooflecture"></asp:RegularExpressionValidator>
<asp:Button ID="bfillattendence" runat="server" Text="To Fill Attendence Click Here"
onclick="FillAttendence_Click" Width="218px" Height="33px" CausesValidation="true" ValidationGroup="upper"/>
我在按钮点击事件
中写下代码string batchname = dpbatchname.SelectedItem.Text.ToString();
int lengthofbatch=batchname.Length;
if(lengthofbatch==2)
{
RegularExpressionValidator1.ValidationExpression = "[1-9][02468]|[02468]";
RegularExpressionValidator1.ErrorMessage = "Only Even No. of Attendence is Valid for Lab.";
}
else if (lengthofbatch == 1)
{
RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]";
RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
}
else
{
RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]";
RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
}
答案 0 :(得分:0)
您是否在验证文本框值? 如果您在服务器端使用正则表达式,那么您需要验证输入(您的文本框) 在下方,并显示消息。
if (Regex.IsMatch(text, reg))
{
}
答案 1 :(得分:0)
添加此行 RequiredFieldValidator1.IsValid = false;
后
RegularExpressionValidator1.ValidationExpression =“[0-9] [0-9] | [0-9]”; RegularExpressionValidator1.ErrorMessage =“Attendence Shold like like 9,50”;