移除]; $"前ASP.Net RangeValidator控件执行脚本 [英] Remove "$" before ASP.Net RangeValidator script executes

查看:205
本文介绍了移除]; $"前ASP.Net RangeValidator控件执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能迫使输入的的onchange脚本之前的运行的的RangeValidator控件的脚本?

我要prevent当用户输入一个美元符号或逗号一个失败的验证。

 函数清理(STR){
重新= / ^ \\ $ |,/克;
返回str.replace(重,); //删除$和,
}<输入类型=文本ID =工资=服务器
的onchange =THIS.VALUE =清理(THIS.VALUE)/>< ASP:RangeValidator控件ID =salaryValidator
=服务器的ErrorMessage =无效号码
的ControlToValidate =工资TYPE =双师型/>

更新:

我决定使用,检查范围,并使用正则表达式的货币一的CustomValidator。感谢迈克尔Kniskern。

 函数IsCurrency(发件人,参数){
VAR输入= args.Value;//检查货币格式。
//防爆pression是http://regexlib.com/REDetails.aspx?regexp_id=70
重新= / ^ \\ $([0-9] {1,3},([0-9] {3},)* [0-9] {3} | [0-9] +)?([ 0-9] [0-9])$ /?;
isCurrency = input.match(重新);如果(isCurrency){
//将字符串转换为数字。
变种数= parseFloat(清理(输入));
如果(数字!= NAN){
//检查范围。
变种分钟= 0;
VAR最大= 1000000;
如果(分钟< =数字功放&;&安培; MAX> =号){
//输入有效。
args.IsValid = TRUE;
返回;
}
}
}//输入无效,如果我们达到这一点。
args.IsValid = FALSE;
返回;
}函数清理(数字){
重新= / ^ \\ $ |,/克;
返回number.replace(重,); //删除$和,
}<输入类型=文本ID =工资=服务器/>< ASP:的CustomValidator ID =saleryValidator的ControlToValidate =工资=服务器
的ErrorMessage =无效号码ClientValidationFunction =IsCurrency/>


解决方案

您是否尝试过使用的CustomerValidator控制和组合的JS清理方法的功能和RangeValidator控件的方法。

How can I force the input's onchange script to run before the RangeValidator's script?

I want to prevent a failed validation when the user enters a dollar sign or comma.

function cleanUp(str) {
	re = /^\$|,/g;
	return str.replace(re, ""); // remove "$" and ","
}

<input type="text" id="salary" runat="server"
onchange="this.value=cleanUp(this.value)" />

<asp:RangeValidator ID="salaryValidator" 
	runat="server" ErrorMessage="Invalid Number"
	ControlToValidate="salary" Type="Double" />

UPDATE:
I decided to use a CustomValidator that checks the range and uses a currency RegEx. Thanks Michael Kniskern.

function IsCurrency(sender, args) {
	var input = args.Value;

	// Check for currency formatting.
	// Expression is from http://regexlib.com/REDetails.aspx?regexp_id=70
	re = /^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$/;
	isCurrency = input.match(re);

	if (isCurrency) {
		// Convert the string to a number.
		var number = parseFloat(CleanUp(input));
		if (number != NaN) {
			// Check the range.
			var min = 0;
			var max = 1000000;
			if (min <= number && max >= number) {
				// Input is valid.
				args.IsValid = true;
				return;
			}
		}
	}

	// Input is not valid if we reach this point.
	args.IsValid = false;
	return;
}

function CleanUp(number) {
	re = /^\$|,/g;
	return number.replace(re, ""); // remove "$" and ","
}       

<input type="text" id="salary" runat="server" />

<asp:CustomValidator ID="saleryValidator" ControlToValidate="salary" runat="server" 
ErrorMessage="Invalid Number" ClientValidationFunction="IsCurrency" />

解决方案

Have you tried using a CustomerValidator control and combined the functionality of the JS cleanup methods and the RangeValidator method.

这篇关于移除]; $&QUOT;前ASP.Net RangeValidator控件执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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