Bgl86
Bgl86

Reputation: 737

Escaping @ in property value

I would like to add an pattern for my email input field:

<input type="email" size="1" required="" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,63}$">

escaping with @@ does not work work

<input type="email" size="1" required="" pattern="[a-z0-9._%+-]+@@[a-z0-9.-]+\.[a-z]{2,63}$">

This does always give me the following exception:

"[" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.

please note that the input is within a @if { } block.

Any idea what I can do?

Upvotes: 3

Views: 169

Answers (1)

Mike Debela
Mike Debela

Reputation: 1950

Parentheses to the rescue! Any time there’s an ambiguity in Razor, you can use parentheses to be explicit about what you want:

<input type="email" size="1" required="" pattern="[a-z0-9._%+-]+@("@")[a-z0-9.-]+\.[a-z]{2,63}$">

Upvotes: 4

Related Questions