使用 Ajax、Jquery 或 JavaScript 在注册表单中添加验证码

Adding Captcha in Registration Form using Ajax , Jquery or JavaScript?

本文关键字:表单 注册表 添加 验证 注册 Ajax Jquery JavaScript 使用      更新时间:2023-09-26

我正在 Jquery 中为注册页面编写代码,当我在注册页面中使用 devexpress 验证码时,那个验证码不是从 jquery.so 验证,我将验证码替换为 jquery 验证码。 任何人都可以帮助我如何在 Jquery 中编写验证码。

这是我

在MVC中使用的一个很好的库,称为.NET的reCAPTCHA插件:https://code.google.com/p/recaptcha/

有一个 Nuget 包可用于它。Nuget ID: recaptcha current verion 1.0.5.0

现在使用它:在您的视图中

在上面的视图中或下方的"提交"按钮:您添加以下代码:

<p>
    @Html.Raw(@Html.GenerateCaptcha())
    @Html.ValidationMessage("captcha")
</p>

然后在控制器操作中添加 RecaptchaControlMvc.CaptchaValidator 属性,并为 recapccha 添加一个额外的 bool 参数,例如 captchaValid

HttpPost, RecaptchaControlMvc.CaptchaValidator]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult Register(RegistrationViewModel model, bool captchaValid)
{
      // If the bool is true The Recapcha validation was successful.
     // If not then you can add a model error with the property name for the: `@Html.ValidationMessage("captcha")`
      if (!isLoan && !captchaValid)
      {
        ModelState.AddModelError("captcha", "Verification word is incorrect. Try again.");
      }
        if (ModelState.IsValid)
        {
           // go an ddo your registration or login
        }
        else
        {
              // handle errors and other messages

        }
        return View(model);
}

图书馆将负责其余的工作。