1

I am writing a snippet to quickly populate register fields for testing purposes

$("#TestRegister").click(function () {
    var rand = Math.floor(Math.random() * 1000) + 1
    $("#UserName").val("Tester" + rand);
    //other fields
    $("#Email").val("example" + rand + "@yahoo.com");//  <==trouble
}

I am writing this code in a script section of cshtml view file. However, email portion gives me trouble. It keeps thinking that code beyond the @ is a code, thus, giving me an error that yahoo is not part of the code. I tried forcing it to recognize @ as a string by placing \ after it, but it gives me parcer errors. Whenever I try search for @, search engines keep ignoring @, and give me unrelated pages.

How do I force @ to be recognized as a part of string?

EDIT: Suggested thread refers to how to recognize C# within Javascript. I am interested in how to make @ as a part of string text in Javascript. As a workaround, I placed "0" in front of @yahoo.com. I want to know if there is more elegant solution.

1
  • 1
    @DanielCorzo Thank you, that answers my question, and this time around, I recognize it as a duplicate. Commented Feb 14, 2017 at 19:24

1 Answer 1

0

try dirty way

String.fromCharCode(64);//returns @ 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.