regex - ASP.NET - define a variable in an ASP page, then use it for a web control attribute's value -
is possible in asp page define variable, use variable web control's attribute value?
i'm trying add validation controls asp.net page, , 1 of them regex control. expression want check field contains numbers, spaces, plus sign , round brackets. (for phone numbers) round brackets special character can't escaped slash (as far can tell), did use regex.escape() construct regular expression, stored string variable. want use variable value regex validation control's expression attribute. possible? if not, how can achieve validation want?
edit1: so, in tag of asp page have this:
<% string phonenumber = "[^0-9 |^" + regex.escape("(") + " |^" + regex.escape(" "); %>
then further down have this:
<asp:regularexpressionvalidator id="mobilephonevalidator" runat="server" controltovalidate="mobilephone" errormessage="mobile phone number must contain numbers." forecolor="red" validationexpression=phonenumber></asp:regularexpressionvalidator>
i'm pretty sure using validationexpression="phonenumber" use actual string phonenumber , not variable. though honest, haven't tried that.
i don't know why spcified string in markup rather code behind, anyway.
assigning string validator looks then:
<asp:regularexpressionvalidator id="mobilephonevalidator" runat="server" controltovalidate="mobilephone" errormessage="mobile phone number must contain numbers." forecolor="red" ></asp:regularexpressionvalidator> <% string phonenumber = "[^0-9 |^" + regex.escape("(") + " |^" + regex.escape(" "); mobilephonevalidator.validationexpression = phonenumber; %>
or define in code file, rather markup.
Comments
Post a Comment