Using javascript regex containing '@' in razorng-pattern not accepting '@' special character in validationHow to validate an email address in JavaScriptIssue with regex when I mix razor and JS and use <text> </text>Email validation function cannot insert inside the cs fileHow to validate an email address in JavaScriptHow do JavaScript closures work?How to validate an email address using a regular expression?Which equals operator (== vs ===) should be used in JavaScript comparisons?Regular expression to match a line that doesn't contain a wordHow do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?
How should one refer to knights (& dames) in academic writing?
Alphanumeric Line and Curve Counting
Why does "git status" show I'm on the master branch and "git branch" does not in a newly created repository?
How could an animal "smell" carbon monoxide?
Coverting list of string into integers and reshaping the original list
What is the point of a constraint expression on a non-templated function?
Is there a typesafe way to get a Database.QueryLocator?
Why do space operations use "nominal" to mean "working correctly"?
Migrating Configuration - 3750G to 3750X
Which GPUs to get for Mathematical Optimization (if any...)?
Interviewing with an unmentioned 9 months of sick leave taken during a job
Will this tire fail its MOT?
''Habitable'' planet close to a star
What details should I consider before agreeing for part of my salary to be 'retained' by employer?
Why does FFmpeg choose 10+20+20 ms instead of an even 16 ms for 60 fps GIF images?
How can I help our ranger feel special about her beast companion?
Why do so many pure math PhD students drop out or leave academia, compared to applied mathematics PhDs?
Should I be able to keep my company purchased standing desk when I leave my job?
How can the electric potential be zero at a point where the electric field isn't, if that field can give a test charge kinetic energy?
What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?
How could a medieval fortress manage large groups of migrants and travelers?
Why doesn't philosophy have higher standards for its arguments?
Is this artwork (used in a video game) real?
What are the first usages of "thong" as a wearable item of clothing, both on the feet and on the waist?
Using javascript regex containing '@' in razor
ng-pattern not accepting '@' special character in validationHow to validate an email address in JavaScriptIssue with regex when I mix razor and JS and use <text> </text>Email validation function cannot insert inside the cs fileHow to validate an email address in JavaScriptHow do JavaScript closures work?How to validate an email address using a regular expression?Which equals operator (== vs ===) should be used in JavaScript comparisons?Regular expression to match a line that doesn't contain a wordHow do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am performing email address validation with javascript in a razor view page.
The regex I am going to use is similar to the one proposed at Validate email address in JavaScript?
However, because the regex contains an '@' character, I am getting parser error when try to run the web app.
my regex looks like
/^...otherpart @* ... other part$/
I tried to add an '@' character to make the in the origin regex ... @@* ..., this eliminated the compilation error but seems to make the regex stops working. (we have used it in another web app that does not use razor engine, so I know it works).
Is there any other way to escape the '@' character?
javascript regex asp.net-mvc asp.net-mvc-4 razor
add a comment |
I am performing email address validation with javascript in a razor view page.
The regex I am going to use is similar to the one proposed at Validate email address in JavaScript?
However, because the regex contains an '@' character, I am getting parser error when try to run the web app.
my regex looks like
/^...otherpart @* ... other part$/
I tried to add an '@' character to make the in the origin regex ... @@* ..., this eliminated the compilation error but seems to make the regex stops working. (we have used it in another web app that does not use razor engine, so I know it works).
Is there any other way to escape the '@' character?
javascript regex asp.net-mvc asp.net-mvc-4 razor
Have you tried wrapping your script block with<text><script>...</script></text>
?
– Jasen
Oct 18 '13 at 3:28
@Jasen I have not tried the <text></text> trick. Will try tomorrow and let you know the result.
– Wei Ma
Oct 18 '13 at 3:32
If you use this script is several places it's probably a good idea to put it in it's own .js file. Individual validation rules, such as max/min, could be put in data- attributes for elements and read via jQuery.
– jfrankcarr
Oct 18 '13 at 3:48
1
@Jasen,@jfankcarr. I have taken your advise and used a separate file and everything is working now. Thanks!
– Wei Ma
Oct 18 '13 at 17:43
add a comment |
I am performing email address validation with javascript in a razor view page.
The regex I am going to use is similar to the one proposed at Validate email address in JavaScript?
However, because the regex contains an '@' character, I am getting parser error when try to run the web app.
my regex looks like
/^...otherpart @* ... other part$/
I tried to add an '@' character to make the in the origin regex ... @@* ..., this eliminated the compilation error but seems to make the regex stops working. (we have used it in another web app that does not use razor engine, so I know it works).
Is there any other way to escape the '@' character?
javascript regex asp.net-mvc asp.net-mvc-4 razor
I am performing email address validation with javascript in a razor view page.
The regex I am going to use is similar to the one proposed at Validate email address in JavaScript?
However, because the regex contains an '@' character, I am getting parser error when try to run the web app.
my regex looks like
/^...otherpart @* ... other part$/
I tried to add an '@' character to make the in the origin regex ... @@* ..., this eliminated the compilation error but seems to make the regex stops working. (we have used it in another web app that does not use razor engine, so I know it works).
Is there any other way to escape the '@' character?
javascript regex asp.net-mvc asp.net-mvc-4 razor
javascript regex asp.net-mvc asp.net-mvc-4 razor
edited May 23 '17 at 11:47
Community♦
11 silver badge
11 silver badge
asked Oct 18 '13 at 3:14
Wei MaWei Ma
1,5174 gold badges30 silver badges64 bronze badges
1,5174 gold badges30 silver badges64 bronze badges
Have you tried wrapping your script block with<text><script>...</script></text>
?
– Jasen
Oct 18 '13 at 3:28
@Jasen I have not tried the <text></text> trick. Will try tomorrow and let you know the result.
– Wei Ma
Oct 18 '13 at 3:32
If you use this script is several places it's probably a good idea to put it in it's own .js file. Individual validation rules, such as max/min, could be put in data- attributes for elements and read via jQuery.
– jfrankcarr
Oct 18 '13 at 3:48
1
@Jasen,@jfankcarr. I have taken your advise and used a separate file and everything is working now. Thanks!
– Wei Ma
Oct 18 '13 at 17:43
add a comment |
Have you tried wrapping your script block with<text><script>...</script></text>
?
– Jasen
Oct 18 '13 at 3:28
@Jasen I have not tried the <text></text> trick. Will try tomorrow and let you know the result.
– Wei Ma
Oct 18 '13 at 3:32
If you use this script is several places it's probably a good idea to put it in it's own .js file. Individual validation rules, such as max/min, could be put in data- attributes for elements and read via jQuery.
– jfrankcarr
Oct 18 '13 at 3:48
1
@Jasen,@jfankcarr. I have taken your advise and used a separate file and everything is working now. Thanks!
– Wei Ma
Oct 18 '13 at 17:43
Have you tried wrapping your script block with
<text><script>...</script></text>
?– Jasen
Oct 18 '13 at 3:28
Have you tried wrapping your script block with
<text><script>...</script></text>
?– Jasen
Oct 18 '13 at 3:28
@Jasen I have not tried the <text></text> trick. Will try tomorrow and let you know the result.
– Wei Ma
Oct 18 '13 at 3:32
@Jasen I have not tried the <text></text> trick. Will try tomorrow and let you know the result.
– Wei Ma
Oct 18 '13 at 3:32
If you use this script is several places it's probably a good idea to put it in it's own .js file. Individual validation rules, such as max/min, could be put in data- attributes for elements and read via jQuery.
– jfrankcarr
Oct 18 '13 at 3:48
If you use this script is several places it's probably a good idea to put it in it's own .js file. Individual validation rules, such as max/min, could be put in data- attributes for elements and read via jQuery.
– jfrankcarr
Oct 18 '13 at 3:48
1
1
@Jasen,@jfankcarr. I have taken your advise and used a separate file and everything is working now. Thanks!
– Wei Ma
Oct 18 '13 at 17:43
@Jasen,@jfankcarr. I have taken your advise and used a separate file and everything is working now. Thanks!
– Wei Ma
Oct 18 '13 at 17:43
add a comment |
3 Answers
3
active
oldest
votes
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 @:@@
1
I've tried a few things...<text>
and beginning the line with@:
but only@@
appears to do the trick. The other option is to use a separate file.
– Jasen
Oct 18 '13 at 3:52
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
2
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
1
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
add a comment |
Put the following inside the regEx instead of @:
@('@')
The above will be rendered to a single @.
Your example will become:
/^...otherpart @('@')* ... other part$/
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
add a comment |
Simply just use double @@
.
It works for me and I think that is the only way.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19440990%2fusing-javascript-regex-containing-in-razor%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 @:@@
1
I've tried a few things...<text>
and beginning the line with@:
but only@@
appears to do the trick. The other option is to use a separate file.
– Jasen
Oct 18 '13 at 3:52
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
2
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
1
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
add a comment |
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 @:@@
1
I've tried a few things...<text>
and beginning the line with@:
but only@@
appears to do the trick. The other option is to use a separate file.
– Jasen
Oct 18 '13 at 3:52
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
2
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
1
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
add a comment |
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 @:@@
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 @:@@
edited Oct 18 '13 at 3:56
answered Oct 18 '13 at 3:28
hwndhwnd
61k4 gold badges58 silver badges101 bronze badges
61k4 gold badges58 silver badges101 bronze badges
1
I've tried a few things...<text>
and beginning the line with@:
but only@@
appears to do the trick. The other option is to use a separate file.
– Jasen
Oct 18 '13 at 3:52
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
2
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
1
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
add a comment |
1
I've tried a few things...<text>
and beginning the line with@:
but only@@
appears to do the trick. The other option is to use a separate file.
– Jasen
Oct 18 '13 at 3:52
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
2
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
1
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
1
1
I've tried a few things...
<text>
and beginning the line with @:
but only @@
appears to do the trick. The other option is to use a separate file.– Jasen
Oct 18 '13 at 3:52
I've tried a few things...
<text>
and beginning the line with @:
but only @@
appears to do the trick. The other option is to use a separate file.– Jasen
Oct 18 '13 at 3:52
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
agreed but it doesn't work.
– Jasen
Oct 18 '13 at 4:01
2
2
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
I would be inclined to put all of that into a separate file instead of writing a funky regex pattern to satisfy the Razor parser. Sometimes it's hard enough understanding a regex pattern without having to think about escaped characters.
– Jasen
Oct 18 '13 at 4:07
1
1
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
Yeah. Separate file worked.
– Wei Ma
Oct 18 '13 at 17:45
add a comment |
Put the following inside the regEx instead of @:
@('@')
The above will be rendered to a single @.
Your example will become:
/^...otherpart @('@')* ... other part$/
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
add a comment |
Put the following inside the regEx instead of @:
@('@')
The above will be rendered to a single @.
Your example will become:
/^...otherpart @('@')* ... other part$/
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
add a comment |
Put the following inside the regEx instead of @:
@('@')
The above will be rendered to a single @.
Your example will become:
/^...otherpart @('@')* ... other part$/
Put the following inside the regEx instead of @:
@('@')
The above will be rendered to a single @.
Your example will become:
/^...otherpart @('@')* ... other part$/
answered Jan 3 '16 at 18:59
Shadi NamroutiShadi Namrouti
2,43220 silver badges24 bronze badges
2,43220 silver badges24 bronze badges
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
add a comment |
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
This should be the accepted answer! Doubling up the @@ changes your REGEX and that's not what you want. still, I wish there were a better way to scape the @ sign in razor, something like @
– Kemuel Sanchez
Nov 16 '17 at 12:35
add a comment |
Simply just use double @@
.
It works for me and I think that is the only way.
add a comment |
Simply just use double @@
.
It works for me and I think that is the only way.
add a comment |
Simply just use double @@
.
It works for me and I think that is the only way.
Simply just use double @@
.
It works for me and I think that is the only way.
edited Mar 21 '17 at 15:18
Alexander Stepaniuk
5,3604 gold badges23 silver badges45 bronze badges
5,3604 gold badges23 silver badges45 bronze badges
answered Mar 20 '17 at 20:36
keyone2693keyone2693
168 bronze badges
168 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19440990%2fusing-javascript-regex-containing-in-razor%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried wrapping your script block with
<text><script>...</script></text>
?– Jasen
Oct 18 '13 at 3:28
@Jasen I have not tried the <text></text> trick. Will try tomorrow and let you know the result.
– Wei Ma
Oct 18 '13 at 3:32
If you use this script is several places it's probably a good idea to put it in it's own .js file. Individual validation rules, such as max/min, could be put in data- attributes for elements and read via jQuery.
– jfrankcarr
Oct 18 '13 at 3:48
1
@Jasen,@jfankcarr. I have taken your advise and used a separate file and everything is working now. Thanks!
– Wei Ma
Oct 18 '13 at 17:43