< script type =" text/javascript " src =" path/to/IDValidator/IDValidator.min.js " charset =" utf-8 " > </ script >
< script type =" text/javascript " src =" path/to/IDValidator/GB2260.min.js " charset =" utf-8 " > </ script >
< script type =" text/javascript " >
//New Normal Instance
var Validator = new IDValidator ( ) ;
//Or to use an instance with address code, GB2260 needs to be introduced
var Validator = new IDValidator ( GB2260 ) ;
</ script >
requirejs . config ( {
paths : {
IDValidator : 'path/to/IDValidator' ,
GB2260 : 'path/to/GB2260'
}
} ) ;
require ( [ "IDValidator" , "GB2260" ] , function ( IDValidator , GB2260 ) {
var Validator = new IDValidator ( ) ;
//Or use address library
var Validator2 = new IDValidator ( GB2260 ) ;
} ) ;
define ( function ( require , exports , module ) {
var IDValidator = require ( 'path/to/IDValidator' ) ;
var Validator = new IDValidator ( ) ;
//Or use address library
var GB2260 = require ( 'path/to/GB2260' ) ;
var Validator2 = new IDValidator ( GB2260 ) ;
} ) ;
npm i id-validator --save
var IDValidator = require ( 'id-validator' ) ;
var GB2260 = require ( 'id-validator/src/GB2260' ) ;
var Validator = new IDValidator ( GB2260 ) ;
var Validator = new IDValidator ( ) ;
var Validator = new IDValidator ( GB2260 ) ;
//The precision of JS medium and long numbers is lost. Please use string to pass values
var id = "123456789012345678" ;
Validator . isValid ( id ) ;
//Legal number return true, illegal return false
Validator . isValid ( id , eighteen ) ;
//Mandatory 18 bit ID
-
The precision of long numbers in JS is lost. Please use string to pass values for long numbers -
Since the 15 digit ID card number does not contain a check code, it can only be judged by whether the address and date exist
Validator . getInfo ( id ) ;
/*
*Example of returned content when the number is valid:
* {
*'addrCode': 100101,//Address code information,
*'addr': 'Dongcheng District, Beijing',//The address information is returned only when GB2260 is passed in during instantiation
*'birth': '1988-01-20',//Date of birth
*'sex ': 1,//Gender, 0 is female, 1 is male
*'checkBit': 'X',//Check bit, only exists when it is 18 bits
*'length': 18//ID card type, 15 bits or 18 bits
* }
*/
Validator . getInfo ( id , eighteen ) ;
//Mandatory 18 bit ID
//Make an 18 digit ID
var ID = Validator . makeID ( ) ;
//Make a 15 digit ID
var ID = Validator . makeID ( true ) ;