A simple statement:
If (! /^ \ W + [\. \ +]? \ W + @ \ W + \. \ W + $/. test (s) Alert ("fail ");
An error occurred while running because @ appears in the regular expression @
So I changed the regular expression to/^ \ W + [\. \ +]? \ W + @ \ W + \. \ W + $/
In Razor's syntax, @ outputs a @ symbol, but the result still reports the same error,
However, I wrote the above to the blank area of the page, but it can be normally output and no error is reported. It can be seen that the razor syntax is written in <SCRIPT> and there is a problem, which cannot be solved after repeated attempts. Finally, the detour is solved:
VaR v = @{
@:/^ \ W + [\. \ +]? \ W + @ \ W + \. \ W + $/
}
If (! V. test (s) Alert ("fail ");
Is there any awkward solution? I mean, if you must write it on the cshtml page, throwing the JS file to the outside will certainly avoid this situation. But what I want to know now is how to solve this problem under the razor syntax, instead of bypassing it.