需要将asp.net c#验证代码转换为客户端验证(jquery或javascript) [英] Need to convert a asp.net c# validation code into clientside Validation(either jquery or javascript)
本文介绍了需要将asp.net c#验证代码转换为客户端验证(jquery或javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static bool ValidateDigit(string sTrn)
{
if (sTrn != "")
{
if (sTrn.Length < 9) return false;
//this function multiplies digits 1,4,7 by 3, digits 2,5,8 by 7, and 3,6,9 by 1, and
//adds the results together. If the total is evenly divisible by 10, then the check digit is ok
//otherwise, it is not. example "good" trn = 263181368
int[] multipliers = new int[3] { 3, 7, 1 }; //multiply each digit by one of these numbers
int s = 0;
int m = 0;
for (int i = 0; i < 9; i++)
{
s += int.Parse(sTrn.Substring(i, 1)) * multipliers[m];
m = ++m < 3 ? m : 0; //reset to first multiplier
}
return (s != 0 && s % 10 == 0) ? true : false;
}
else
return false;
}
推荐答案
嗨sharonjoy,
这里我根据你的逻辑创建了一个jQuery方法,请查看: -
Hi sharonjoy,
Here I have created one jQuery method as per your logic, please check this out :-
function ValidateNumber(strNo) {
if (strNo == '' || strNo.length < 9) return false;
var b = false;
var s = 0;
var m = 0;
var multipliers = [3, 7, 1];
.each(strNo, function (i,n){
if (n == 1 || n = = 4 || n == 7 )s + =(n * 3 );
如果(n == 2 || n == 5 || n == 8 )s + =(n * 7 );
如果(n == 3 || n == 6 || n == 9 )s + =(n * 1 );
});
b =(s!= 0 && s% 10 == 0 )? true : false ;
return b;
}
.each(strNo, function (i, n) { if (n == 1 || n == 4 || n == 7) s += (n * 3); if (n == 2 || n == 5 || n == 8) s += (n * 7); if (n == 3 || n == 6 || n == 9) s += (n * 1); }); b = (s != 0 && s % 10 == 0) ? true : false; return b; }
希望这对您有所帮助。
Hope this will definitely of help to you.
var x = new Array(3, 7, 1);
var s = 0;
var m = 0;
var j = 0;
for (i = 0; i < 9; i++) {
if (m == 0)
j = 3;
else if (m == 1)
j = 7;
else if (m == 2)
j = 1;
s += parseInt(vNumbr[i], 10) * j;
m = ++m;
if (m >= 3) {
m = 0
}
}
return (s != 0 && s % 10 == 0) ? true : false;
这篇关于需要将asp.net c#验证代码转换为客户端验证(jquery或javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文