joecool2005 Posted September 24, 2007 Share Posted September 24, 2007 HiWhen I do this Dim regExp As RegularExpressionValidator regExp = New RegularExpressionValidator regExp.ValidationExpression = "[a-z][0-9]" Response.Write(regExp.isValid) How do I assign value on "regExp" to validate with my regular expression?For example: I want to assign value "ABC" and validate .ThxJoe Link to comment Share on other sites More sharing options...
aspnetguy Posted September 24, 2007 Share Posted September 24, 2007 use this to set the control you want to validate regExp.ControlToValidate = "textbox1" Link to comment Share on other sites More sharing options...
joecool2005 Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks for your replyBy adding regExp.ControlToValidate = "textbox1" to my code, now I have a code like this <script runat=server>Sub ValidateForm(ByVal sender As Object, ByVal e As EventArgs)Dim regExp As RegularExpressionValidator regExp = New RegularExpressionValidator regExp.ValidationExpression = "[a-z][0-9]" regExp.ControlToValidate = "textbox1" Response.Write(regExp.isValid)end sub</script><asp:TextBox id="textbox1" runat="server" /><asp:Button id=Button1 value="submit" runat="server" OnClick="ValidateForm" /> And it does not work inside of the functionI would like to run inside a function. What should I change? Link to comment Share on other sites More sharing options...
jesh Posted September 26, 2007 Share Posted September 26, 2007 Why does it need to be created in an event handler? And if it needs to be created on the server, dynamically, why not do so in the Page_Load?If it doesn't need to be dynamic, you can put it directly in the aspx: <asp:TextBox id="textbox1" runat="server" /><asp:RegularExpressionValidator runat="server" ControlToValidate="textbox1" ErrorMessage="Doesn't match expression" ValidationExpression="[a-z][0-9]" /><asp:Button id=Button1 value="submit" runat="server" /> Also keep in mind that "[a-z][0-9]" will match any of the following:d4gggqw7gww%$#$@%@@%@@%h6(AF@@kl Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.