50分求救:用JAVASCRIPT写MOD/10验证卡号的例子,在线等待中。。。

老李 2002-05-24 11:17:35
谢谢了!
...全文
348 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
老李 2002-05-24
  • 打赏
  • 举报
回复
16位全数字的。
孟子E章 2002-05-24
  • 打赏
  • 举报
回复
你的卡号什么特征?
qiushuiwuhen 2002-05-24
  • 打赏
  • 举报
回复
<form>
<input id=tt value=3141592653587><input type=button value=check onclick=check(tt.value)>
</form>
<script>
function check(str){
if(!isCreditCard(str))alert("未通过")
alert("通过第一层验证:"+str)
}
function isCreditCard(st) {
// Encoding only works on cards with less than 19 digits
if (st.length > 19)
return (false);

sum = 0; mul = 1; l = st.length;
for (i = 0; i < l; i++) {
digit = st.substring(l-i-1,l-i);
tproduct = parseInt(digit ,10)*mul;
if (tproduct >= 10)
sum += (tproduct % 10) + 1;
else
sum += tproduct;
if (mul == 1)
mul++;
else
mul--;
}
// Uncomment the following line to help create credit card numbers
// 1. Create a dummy number with a 0 as the last digit
// 2. Examine the sum written out
// 3. Replace the last digit with the difference between the sum and
// the next multiple of 10.

// document.writeln("<BR>Sum = ",sum,"<BR>");
// alert("Sum = " + sum);

if ((sum % 10) == 0)
return (true);
else
return (false);

} // END FUNCTION isCreditCard()
</script>
老李 2002-05-24
  • 打赏
  • 举报
回复
老是出错,秋水你调试过吗?
qiushuiwuhen 2002-05-24
  • 打赏
  • 举报
回复
view-source:http://developer.netscape.com/docs/examples/javascript/formval/FormChek.js

代码
function isCreditCard(st) {
// Encoding only works on cards with less than 19 digits
if (st.length > 19)
return (false);

sum = 0; mul = 1; l = st.length;
for (i = 0; i < l; i++) {
digit = st.substring(l-i-1,l-i);
tproduct = parseInt(digit ,10)*mul;
if (tproduct >= 10)
sum += (tproduct % 10) + 1;
else
sum += tproduct;
if (mul == 1)
mul++;
else
mul--;
}
// Uncomment the following line to help create credit card numbers
// 1. Create a dummy number with a 0 as the last digit
// 2. Examine the sum written out
// 3. Replace the last digit with the difference between the sum and
// the next multiple of 10.

// document.writeln("<BR>Sum = ",sum,"<BR>");
// alert("Sum = " + sum);

if ((sum % 10) == 0)
return (true);
else
return (false);

} // END FUNCTION isCreditCard()

qiushuiwuhen 2002-05-24
  • 打赏
  • 举报
回复
http://developer.netscape.com/docs/examples/javascript/formval/overview.html

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧