Visual studio 12 and regular expressions error

I am getting a strange error in VS2012.

I've got the following script:

<script type="text/javascript">

    function validateEmail($email) {
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        if( !emailReg.test( $email ) ) {
            return false;
        } else {
            return true;
        }
    }

</script>

This throws all sot of errors in the IDE, and in VS2010 used to run OK.

What could be wrong?

Thanks!

Answers


Let me guess... are you using Razor (a cshtml page)? If so, this problem is caused because the IDE thinks that the part @([\w-]+\.) is a Razor expression and then, the javascript reg ex is looking for the missing parenthesis. To fix this, you need to escape the @ by using a @@ So your code will be:

<script type="text/javascript">

    function validateEmail($email) {
        var emailReg = /^([\w-\.]+@@([\w-]+\.)+[\w-]{2,4})?$/;
        if( !emailReg.test( $email ) ) {
            return false;
        } else {
            return true;
        }
    }

</script>

Need Your Help

Hide window from taskbar

python qt pyqt

I'm trying to minimize a window to the tray, but it seems it refuses to hide from the taskbar. I've spent a little time and distilled the problem code down to this. It's not mcuh so I'm wondering i...

Python How to get set bit

python bit-manipulation bit

Say I have a number that in memory looks like this (or similar, I don't know exactly how Python stores numbers):

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.