Skip to content

Commit

Permalink
增加测试用例与examples,更新README
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-zone committed Jan 28, 2015
1 parent ef9ed31 commit 590317e
Show file tree
Hide file tree
Showing 8 changed files with 2,276 additions and 225 deletions.
223 changes: 0 additions & 223 deletions IDValidator.js

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var Validator = new IDValidator();

```

提示:直接引入IDValidator就可以使用
提示:所有API引入IDValidator.js就可以使用

GB2260.js为GB 2260地址码数据,用于分析地址信息,在实例化时传入,可以不使用。

Expand Down Expand Up @@ -112,7 +112,7 @@ var ID = Validator.makeID();
//制造一个15位ID
var ID = Validator.makeID( true );
```
详见 `[examples](https://github.com/mc-zone/IDValidator/tree/master/examples/)` .
详见 [`examples`](https://github.com/mc-zone/IDValidator/tree/master/examples/) .

##参考资料
GB 11643-1999 公民身份证号码
Expand Down
61 changes: 61 additions & 0 deletions examples/client-side/lib/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
requirejs.config({
baseUrl:'../../src/',
paths: {
IDValidator: 'IDValidator',
GB2260: 'GB2260'
}
});
//调用依赖
require(["IDValidator","GB2260"], function(IDValidator,GB2260) {
function log() {
for(var i=0;i<arguments.length;i++){
var m = arguments[i];
if( typeof m == 'object' ){
for( var k in m ){
if( m.hasOwnProperty(k) ){
log(k+':',m[k]);
}
}
}else{
var p = document.createElement('p');
p.innerText = m.toString();
document.body.appendChild(p);
}
}
}

var testId = "371001198010082394";
var fakeId = "345955198706122245";
var fifteenId = "431389760616601";

var Validator = new IDValidator();

//检测是否合法
log( '\nID:'+testId+'的合法性为:\n', Validator.isValid( testId ) );
log( '\n假ID:'+fakeId+'的合法性为:\n', Validator.isValid( fakeId ) );
//15位
log( '\n15位ID:'+fifteenId+'的合法性为:\n', Validator.isValid( fifteenId ) );

var Validator2 = new IDValidator( GB2260 );

//输出分析信息
log( '\nID:'+testId+'的信息为(带地址):\n', Validator2.getInfo( testId ) );

//伪造一个ID
var makeID = Validator.makeID();
log( '\n制作的ID:'+makeID+'的信息为:\n',Validator2.getInfo( makeID ) );


//伪造一个15位ID
var makeID2 = Validator.makeID(true);
log( '\n制作的15位ID:'+makeID2+'的信息为:\n',Validator2.getInfo( makeID2 ) );


//随机地址码伪造一个ID
var makeID3 = Validator2.makeID();
log( '\n随机地址码制作的ID:'+makeID3+'的信息为:\n',Validator2.getInfo( makeID3 ) );




});
Loading

0 comments on commit 590317e

Please sign in to comment.