Using javascript regex containing '@' in razor

ID : 274323

viewed : 35

Tags : javascriptregexasp.net-mvcasp.net-mvc-4razorjavascript





Top 5 Answer for Using javascript regex containing '@' in razor

vote vote

92

You can add another @ in front of it to escape @@, try leaving out the quantifer *. If this doesn't seem to work then add <text></text> around the function, it tells Razor to not parse the contents. Alternatively you can put Javascript in a separate file to accomplish your needs.

If for some reason you have multiple @@ in your string, place code blocks ahead @:@@

vote vote

88

Put the following inside the regEx instead of @:

@('@') 

The above will be rendered to a single @.

Your example will become:

/^...otherpart @('@')* ... other part$/ 
vote vote

70

Simply just use double @@.
It works for me and I think that is the only way.

vote vote

65

It's better to use @('@') instead of @@ (not working for me). Example

<input class="form-control" pattern="^[a-zA-Z@('@')]{5,20}$"/> 
vote vote

57

Top 3 video Explaining Using javascript regex containing '@' in razor







Related QUESTION?