c# - Store regular expressions for use throughout web application -


i have web application contains many forms textbox fields on dates , urls etc.

i using <asp:regularexpressionvalidator> validate textbox content , wondered if there way centrally store expressions using in web.config file can reference them each time add <asp:regularexpressionvalidator>, rather having type out entire regex i.e.

regex store

string urlregex = "(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})" 

web form

<asp:regularexpressionvalidator validationexpression=urlregex> </asp:regularexpressionvalidator> 

thanks in advance

i typically create resources file in asp.net app_globalresources folder centralize string constants , reference string in markup. example created regexstrings.resx resource file , added key url value containing regular expression string:

<asp:textbox id="urltextbox" runat="server"></asp:textbox> <asp:regularexpressionvalidator id="urlregex" runat="server"                                      errormessage="invalid url."                                  controltovalidate="urltextbox"                                      validationexpression="<%$ resources:regexstrings, url %>" /> 

see asp.net web page resources overview details


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -