test

package com.dwh.util;

import java.util.Arrays;

public class BizLicenseTools {

   
public static boolean isContainLetter(String str){
        
for (int i = 0; i < str.length(); i++) {
           
if(Character.isLetter(str.charAt(i))){
               
return true;
            }
        }
       
return false;
    }

   
public static boolean isContainInvalidChr(String str){

       
String[] invalid = { "I","O","Z","S","V"};

       
System.out.println("check invalid character");

       
for (int i = 0; i < str.length(); i++) {
           
Character chr = str.charAt(i);
           
System.out.println("current character:" + chr.toString());
            
if(Arrays.asList(invalid).contains(chr.toString())){
               
System.out.println("Contain the invalid Character: " + chr.toString());
               
return true;
            }
        }
       
return false;
    }

   
public static boolean isSameNumbers(String str){

       
for (int i = 0; i < str.length(); i++) {

               
if (str.charAt(i) != str.charAt(0) && !Character.isDigit(str.charAt(i)))
                   
return false;
        }

       
return true;
    }


   
//1 BusinessLicenseType = 3  2:不符合验证   3 符合验证规则
    public static String isValidBizLicenseNum(String bizLicenseType, String bizLicenseNumber){

       
String BusinessLicenseResult = "1";

       
if (bizLicenseType.equals("3")){

           
if( bizLicenseNumber.length() == 15 && !isSameNumbers(bizLicenseNumber)){
               
if(isContainLetter(bizLicenseNumber)){
                    BusinessLicenseResult=
"2";
                }
else{
                    BusinessLicenseResult=
"3";
                }
            }
else if( bizLicenseNumber.length() == 18  && !isSameNumbers(bizLicenseNumber)){
               
if(isContainInvalidChr(bizLicenseNumber)){
                   
System.out.println("Is Contain Invalid Character Validation");
                    BusinessLicenseResult=
"2";
                }
else{
                    BusinessLicenseResult=
"3";
                }
            }
else {
                BusinessLicenseResult =
"2";
            }
        }

       
return BusinessLicenseResult;

    }

   
public static void main(String[] args){

       
String input = "121111Y111I1111111";
       
String bizType = "3";
       
String result = isValidBizLicenseNum(bizType,input);
       
System.out.println(result);
    }
}

 

你可能感兴趣的:(sqlserver)