JavaScript 简单的类似Captcha的验证JavaScript脚本,使用jQuery(表单)验证插件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 简单的类似Captcha的验证JavaScript脚本,使用jQuery(表单)验证插件相关的知识,希望对你有一定的参考价值。

jQuery(document).ready(function() {	
	var send_email_form = jQuery("form#my-form");
	var lowerBound = 1;
	var upperBound = 10;
	// to generate random numbers between a range that starts somewhere other than
	// zero use this formula where m is the lowest possible integer value of the range
	// and n equals the top number of the range.
	// Math.floor(Math.random() * (n - m + 1)) + m
	
	// generate random numbers between lowerBound and upperBound (inclusive)
	var a = Math.floor(Math.random() * (upperBound - lowerBound + 1)) + lowerBound;
	var b = Math.floor(Math.random() * (upperBound - lowerBound + 1)) + lowerBound;
			
	jQuery("label#arithmetic_expression").html(a + " + " + b + " = ");
	jQuery("input#eqtn_soln").val(a+b);	
	
	var validation_rules = {
		name: "required",
		email: {
		 	required: true,
		 	email: true
		 },
		subject: "required",
		message: "required",
		sum: {
			required: true,
			equalTo: "input#eqtn_soln"
		}
	};
	
	var validation_messages = {
		name: "please enter your name",
		email: {
		 	required: "Please enter your email address",	
		 	email: "Please enter a valid email address"				
		 },
		subject: "please enter a message subject",
		message: "please enter the message",
		sum: {
			required: "please answer the equation",
			equalTo: "please answer the equation correctly"
		}					
	};	
	
	//form validation with Javascript

	send_email_form.validate({
		rules: validation_rules,
		messages: validation_messages,
		//errorClass: "form-error-style",
		errorPlacement: function(error, element){
			// places the error message after the element one line break below
			error.insertAfter(jQuery("<br />").insertAfter(element));
		}		
	});		
});

以上是关于JavaScript 简单的类似Captcha的验证JavaScript脚本,使用jQuery(表单)验证插件的主要内容,如果未能解决你的问题,请参考以下文章

PHP 简单的图像CAPTCHA

如何使用 c# 以编程方式在 domino 服务器中获取 CA 配置的验证者名称列表?

比特币技术 --- 交易的验签原理

阿里云 windows 2008 使用Thinkphp5 captcha验证码不显示问题

BNUOJ 52506 Captcha Cracker

SQL任务帮助请