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.

Vadzim Savenok
  • 930
  • 3
  • 14
  • 37

1 Answers1

0

try dirty way

String.fromCharCode(64);//returns @ 
darkside
  • 47
  • 5