Code Monkey home page Code Monkey logo

generator's People

Contributors

xbeginagain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

generator's Issues

统一社会信用代码校验

统一社会信用代码校验,校验存在问题

例如: 12440600MB2C07549J

`

import java.util.HashMap;
import java.util.Map;

public class HelloWorld {
public static void main(String []args) {
HelloWorld helloWorld = new HelloWorld();

    boolean b = helloWorld.validate18("12440600MB2C07549J");
    System.out.println(b);
}

public boolean validate18(String bizNo) {

    String regex = "^([0-9ABCDEFGHJKLMNPQRTUWXY]{2})([0-9]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{10})$";
    if (!bizNo.matches(regex)) {
        return false;
    }

    String baseCode = "0123456789ABCDEFGHJKLMNPQRTUWXY";
    char[] baseCodeArray = baseCode.toCharArray();
    Map<Character, Integer> codes = new HashMap<Character, Integer>();
    for (int i = 0; i < baseCode.length(); i++) {
        codes.put(baseCodeArray[i], i);
    }

    char[] businessCodeArray = bizNo.toCharArray();
    Character check = businessCodeArray[17];
    if (baseCode.indexOf(check) == -1) {
        return false;
    }

    int[] ws = { 1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28 };
    int sum = 0;
    for (int i = 0; i < 17; i++) {
        Character key = businessCodeArray[i];
        if (baseCode.indexOf(key) == -1) {
            return false;
        }
        sum += (codes.get(key) * ws[i]);
    }

    int c18 = 31 - sum % 31;
    if (c18 == 31) {
        c18 = 0;
    }
    return c18 == codes.get(check);

}

}

`

统一社会信用代码校验写错了

var str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var wi =[1,3,9,27,19,26,16,17,20,29,25,13,8,24,10,30,28];
var sum = 0;
for (var i = 0; i < 17; i++) {
sum += str.indexOf(creditCode.charAt(i)) * wi[i];
}

str里面不能有I O Z S V

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.