如何在mvc中的jquery中使用@符号 [英] How To use @ symbol in jquery in mvc

查看:18
本文介绍了如何在mvc中的jquery中使用@符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 if 条件下在 javascript 中使用 @ 符号.但它向我显示了一个错误.

I am trying to use @ symbol in javascript in if condition. but it is showing me an error.

if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) {
                    alert('yes');
                    strength += 1
                }

它向我展示了这个错误.

It is Showing me this error.

推荐答案

可以输入两次,如下图:

You can type it twice as shown below:

if (password.match(/(.*[!,%,&,@@,#,$,^,*,?,_,~].*[!,%,&,@@,#,$,^,*,?,_,~])/)) {
    alert('yes');
    strength += 1
}

因为 @ 是 razor 语法的特殊字符.您可以通过键入另一个 @

Since @ is a special character for razor syntax. You can escape it by typing another @

更新

由于您在正则表达式中尝试它并且如上所述,@@ 只是解决了编译错误但在使用正则表达式时给出了错误的结果,请尝试:

Since you are trying it in regex and as mentioned, @@ just solves the compilation error but gives wrong results while using the regex, please try:

if (password.match(/(.*[!,%,&,@('@'),#,$,^,*,?,_,~].*[!,%,&,@('@'),#,$,^,*,?,_,~])/)) {
    alert('yes');
    strength += 1
}

@('@') 将被 razor 转换成 @ 并且应该给你想要的结果.

The @('@') will be converted into @ by razor and should give you the desired result.

这篇关于如何在mvc中的jquery中使用@符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆