c# - ASP.NET, JQuery - Sharing regular expressions -


If you have both clients (JavaScript) and server side code (C #, vb.net) and to avoid duplication Want to store in one place where you store them?

I can use the register and write Riyazax as a string, but just wondering if someone is more elegant.

You can store them as a protected variable in the code-behind of your ASP.NET page, and then use data-driven expressions You can store them in your JavaScript as a public variable ...

In your ASPX page:

  & lt; Script type = "text / javascript" & gt; Var regexPhone = new RegExp ("& lt;% # regexPhone%>";); Var regexEmail = new RegExp ("& lt;% # regexEmail%>"); Var regexBlah = new RegExp ("& lt;% # regexBlah%>"); & Lt; / Script & gt;  

Back in your code:

  protected string regexPhone = "put the regex string here"; Protected string regexEmail = "put the regex string here"; Protected string regexBlah = "put the regex string here"; Protected Zero Page_load (Object Sender, EventArgse E) {// We want to call Databand () on page so that we can use Databading Expression DataBind (); }  

I have never tried this exact approach before, I think it will work: -P I know that it helps!

Note: There will be a potential warning that the .NET regular expression tastes may differ from the JavaScript regular expression. There is an effective effect of great masses goiwats that can be helpful.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -