Number Validators Validation of Business License Number and Unified Social Credit Code

Posted by andz on Sat, 11 May 2019 17:49:53 +0200

Essentially, the business license number and the unified social credit code are two completely different coding rules, and the recognition results are only shared by the administrative divisions. But because of the reasons for the coexistence of the two codes, if it is necessary to uniquely mark an enterprise in the system, it is still possible to use the business license number or the unified social credit code. Recognition.

The length of business license number is 15 bits according to industrial and commercial regulations, and the uniform social credit code is 18 bits according to national regulations. You can use other websites (e.g. on the basis of verification of such databases). Enterprise check ) To further verify the existence of enterprises.

In NumberValidators, this section validates the relevant content under NumberValidators. Business Registration Nos. You can use here See the specific source code.

IRegistrationNoValidator agrees on the specification of the validation to be implemented.

    /// <summary>
    /// Business Registration Code/Unified Social Credit Code Verification Interface
    /// </summary>
    public interface IRegistrationNoValidator<out TResult> : IValidator<TResult>
        where TResult : RegistrationNoValidationResult, new()
    {
        /// <summary>
        /// Dictionary data of administrative divisions for validation
        /// </summary>
        IValidationDictionary<int, string> Dictionary { get; set; }
        /// <summary>
        /// Number Length
        /// </summary>
        RegistrationNoLength RegistrationNoLength { get; }
        /// <summary>
        /// Verify that the number is correct
        /// </summary>
        /// <param name="code">business registration code to be verified/Unified Social Credit Code</param>
        /// <param name="valid Limit"> administrative division validation restriction, because of the existence of business administration code, the default is null</param>.
        /// <returns></returns>
        TResult Validate(string code, AreaValidLimit? validLimit = null);
    }

Verification results are defined as follows:

  • RegistrationNoValidationResult default validation result class
  • RegistrationNo15 Validation Result Business License Specific Validation Results Class
  • RegistrationNo18 Validation Result Unified Social Credit Code Specific Validation Result Class

The RegistrationNoValidation Result code is as follows

    /// <summary>
    /// Registry Code Universal Verification Result Class
    /// </summary>
    public class RegistrationNoValidationResult : ValidationResult
    {
        /// <summary>
        /// Coding of administrative divisions or administrative organs for Industry and Commerce
        /// </summary>
        public int AreaNumber { get; internal set; }
        /// <summary>
        /// Identity Card Issuing Administrative Region or industry and commerce administrative authority (identifying the deepest Depth area) can obtain the complete name through FullName
        /// Note that this might be null
        /// </summary>
        public Area RecognizableArea { get; internal set; }
        /// <summary>
        /// Number Length
        /// </summary>
        public RegistrationNoLength RegistrationNoLength { get; internal set; }
        /// <summary>
        //Checksum code
        /// </summary>
        public char CheckBit { get; internal set; }
    }

Registration No15 Validation Result includes the exclusive identification information of business license on the basis of Registration NoValidation Result, through which you can know whether the enterprise is a domestic enterprise, a foreign enterprise or an individual.

   /// <summary>
    /// Specialized Verification Result Class of Registration Number of Market Subjects in Industrial and Commercial Administration
    /// </summary>
    public class RegistrationNo15ValidationResult : RegistrationNoValidationResult
    {
        /// <summary>
        //Sequential code
        /// </summary>
        public int SequenceNumber { get; internal set; }
        /// <summary>
        /// Enterprise type
        /// </summary>
        public EnterpriseType EnterpriseType
        {
            get
            {
                var comp = this.SequenceNumber / 10000000;
                if (comp <= (int)EnterpriseType.Domestic)
                {
                    return EnterpriseType.Domestic;
                }
                else if (comp <= (int)EnterpriseType.Foreign)
                {
                    return EnterpriseType.Foreign;
                }
                else { return EnterpriseType.Individual; }
            }
        }
    }

Registration No18 Validation Result is based on the Registration NoValidation Result, which contains the exclusive information of the social unified credit code, through which you can know the registration management department and its organization code.

    /// <summary>
    /// Unified Social Credit Code Specialized Verification Result Class for Legal Persons and Other Organizations
    /// </summary>
    public class RegistrationNo18ValidationResult : RegistrationNoValidationResult
    {
        /// <summary>
        /// Registration Administration Code Logo
        /// </summary>
        public ManagementCode ManagementCode { get; internal set; }
        /// <summary>
        /// Institutional Category Code Mark under Registration Administration Department
        /// </summary>
        public ManagementKindCode ManagementKindCode { get; internal set; } = ManagementKindCode.NonSpecific;
        /// <summary>
        /// Organizational code, follow GB/T 11714-1997
        /// </summary>
        public string OrganizationCode { get; internal set; }
    }

If the validation fails, the Errors attribute contains the reasons for the validation failure. The list of specific reasons for the error is as follows.

    /// <summary>
    /// Error prompt information class
    /// </summary>
    internal class ErrorMessage
    {
        /// <summary>
        /// String empty
        /// </summary>
        public const string Empty = "Business Registration Code/Unify Social Credit Code to Empty";
        /// <summary>
        /// Number error
        /// </summary>
        public const string Error = "Incorrect business registration code/Unified Social Credit Code";
        /// <summary>
        /// Invalid Registration Administration Code
        /// </summary>
        public const string InvalidManagement = "Invalid Registration Administration Code";
        /// <summary>
        /// Invalid Registration Administration Agency Category Code
        /// </summary>
        public const string InvalidManagementKind = "Invalid Registration Administration Agency Category Code";
        /// <summary>
        /// Invalid organization code
        /// </summary>
        public const string InvalidOrganizationCode = "Invalid organization code";
        /// <summary>
        /// Failure to identify administrative divisions
        /// </summary>
        public const string InvalidArea = "Failure in identifying industrial and commercial administrative organs or administrative divisions";
        /// <summary>
        /// Error Check Code
        /// </summary>
        public const string InvalidCheckBit = "Error Check Code";
        /// <summary>
        /// Invalid implementation
        /// </summary>
        public const string InvalidImplement = "Not found or invalid {0} Bit Business Registration Code/Realization of Unified Social Credit Code";
        /// <summary>
        /// Length error
        /// </summary>
        public const string LengthOutOfRange = "Business Registration Code/Unifying Social Credit Code {0} position";
    }

Consistent with other validation classes, RegistrationNoValidator Helper can automatically identify whether the number to be identified is a business license number or a social unified credit code. Of course, because it is possible to identify which number is not, the final identification results may be in RegistrationNoValidation Result, RegistrationNoValidation Result and RegistrationNo18Validation Result. One of them.

Finally, a simple use example

            Console.WriteLine("***Business Registration Code/Unified Social Credit Code***");
            string[] rnArr = { "110108000000016", "91320621MA1MRHG205" };
            foreach (var rn in rnArr)
            {
                var valid = RegistrationNoValidatorHelper.Validate(rn, validLimit: null);
                Console.WriteLine("{0}Verification results:{1} length{2} Name of administrative division({3}) Validation result type:{4}", rn, valid.IsValid, valid.RegistrationNoLength, valid.RecognizableArea.FullName, valid);
            }
            Console.WriteLine("Random Business Registration Code:" + new RegistrationNo15Validator().GenerateRandomNumber());
            Console.WriteLine("Random Unified Social Credit Code:" + new RegistrationNo18Validator().GenerateRandomNumber());

Topics: C# Attribute