Jump to content

regular expression


Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...