代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
JS
】
随机生成信用卡卡号
作者:
Duncan
/ 发布于
2014/11/18
/
758
/* Javascript credit card number generator Copyright (C) 2006-2012 Graham King graham@gkgk.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. www.darkcoding.net */ var visaPrefixList = new Array( "4539", "4556", "4916", "4532", "4929", "40240071", "4485", "4716", "4" ); var mastercardPrefixList = new Array( "51", "52", "53", "54", "55" ); var amexPrefixList = new Array( "34", "37" ); var discoverPrefixList = new Array("6011"); var dinersPrefixList = new Array( "300", "301", "302", "303", "36", "38" ); var enRoutePrefixList = new Array( "2014", "2149" ); var jcbPrefixList = new Array( "35" ); var voyagerPrefixList = new Array("8699"); function strrev(str) { if (!str) return ''; var revstr=''; for (i = str.length-1; i>=0; i--) revstr+=str.charAt(i) return revstr; } /* 'prefix' is the start of the CC number as a string, any number of digits. 'length' is the length of the CC number to generate. Typically 13 or 16 */ function completed_number(prefix, length) { var ccnumber = prefix; // generate digits while ( ccnumber.length < (length - 1) ) { ccnumber += Math.floor(Math.random()*10); } // reverse number and convert to int var reversedCCnumberString = strrev( ccnumber ); var reversedCCnumber = new Array(); for ( var i=0; i < reversedCCnumberString.length; i++ ) { reversedCCnumber[i] = parseInt( reversedCCnumberString.charAt(i) ); } // calculate sum var sum = 0; var pos = 0; while ( pos < length - 1 ) { odd = reversedCCnumber[ pos ] * 2; if ( odd > 9 ) { odd -= 9; } sum += odd; if ( pos != (length - 2) ) { sum += reversedCCnumber[ pos +1 ]; } pos += 2; } // calculate check digit var checkdigit = (( Math.floor(sum/10) + 1) * 10 - sum) % 10; ccnumber += checkdigit; return ccnumber; } function credit_card_number(prefixList, length, howMany) { var result = new Array(); for (var i = 0; i < howMany; i++) { var randomArrayIndex = Math.floor(Math.random() * prefixList.length); var ccnumber = prefixList[ randomArrayIndex ]; result.push( completed_number(ccnumber, length) ); } return result; } 调用方法: 将上面的代码保存为gencc.js文件 <html> <head> <script src="gencc.js" type="text/javascript"></script> </head> <body> <h3>VISA:</h3> <script> var visa = credit_card_number(visaPrefixList, 16, 3); document.write( visa ); </script> <h3>Amex:</h3> <script> var amex = credit_card_number(amexPrefixList, 15, 3); document.write( amex ); </script> </body> </html>
试试其它关键字
同语言下
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
可能有用的
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
Duncan
贡献的其它代码
(
49
)
.
设置HTTP 下载图片
.
计算一个目录的大小
.
浮云效果
.
随机生成信用卡卡号
.
重命名数据库
.
通过文件流读取一个已存在的文件
.
CLI 把16进制字符串转换成数字存到数组
.
显示中文日期
.
在标题栏上显示当前日期
.
创建一个返回上一页的按钮
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3