3 Replies Latest reply: Feb 1, 2014 4:11 PM by EJP RSS

    security number validation

    Tshifhiwa

      hi i have to validate security number based on tHIS REQUEST

       

      if the SECURITYNNUBER IS INVALID UNDER THE SECURITYNUMBER attribute,it must reject(Date & algorith). To override the normal validation,the subject must contain INVALIDSECURITYNUMBER. The incorrect ID number must still reflect in the SECURITYNUMBER attribute.

       

      THE FIRST 6 DIGIT IS DATE

       

      EXAMPLE 7701205334086

       

      public boolean val_SECURITYNUMBER()

          {

              boolean flag = true;

              String u_Securtynr = transactionFile.getS_securtynumber();

                            

              // 1. Invalid securty number if completed

            

                  if(!isBlank(u_Securtynr))

                  {

                      //if(isValidPattern(u_Securtynr, "[0-9]{13}") && isValidDate(u_Securtynr.substring(0,6), "[0-9]{6}", "yyMMdd"))

                      //{

                          if(!isValidsecuritynumber(u_Securtynr))

                          {

                              if(!isEqualTo(monetaryDetail.getmSubject(), "INVALIDSECURITYNUMBER"))

                              {

                                 

                                    System.out.println("SECURITY " + ERRORCODE 222)

       

                              }

                             

                          }

                      }else

                      {

                         

                            System.out.println("SECURITY " + ERRORCODE 322)

       

                      }

                  }

       

      public boolean isValidPattern(String s_value, String s_pattern)

           {

              boolean flag = false;

              

              if(Pattern.matches(s_pattern, s_value))

              {

                  flag = true;

              }

              

               return flag;

           }

          

       

       

      public boolean isValidsecuritynumber(String s_idNumber)

          {

              //boolean flag = false;

             

              String sIdNumber = s_idNumber;

              int odd = 0;

              int num ;

             

              if(!isValidPattern(sIdNumber, "[0-9]{13}"))

              {

                  return false;

              }else

              {           

                  try

                  {

                  //(1)Add all numbers at Odd places

                  for(int x = 0; x < 6; x++)

                  {

                      odd = Integer.parseInt(sIdNumber.charAt(2*x)+"") + odd;

                  }

       

                  int Total_A = odd;

       

                  //(2)Combine the even numbered

                  String s_even = "";

                  for(int y = 0; y <6; y++)

                  {

                      s_even += sIdNumber.charAt(2*y + 1);

                  }

                 

                  num = (Integer.parseInt(s_even));

                  //(3) s_even x 2

                  int numID = num * 2;

                  String s_Total3 = numID+"";

                  //(4)

                  int total4 = 0;

                  for(int z=0;z<s_Total3.length();z++)

                  {

                      total4 += Integer.parseInt(s_Total3.charAt(z)+"");

                  }

                             

                  int i_secondLast = Total_A + total4;

                  String s_secondLast = i_secondLast+"";

                 

                 

                  int i_total5 = 10-(Integer.parseInt(s_secondLast.charAt(1)+""));

                 

                  if(i_total5 == 10)

                  {

                      i_total5 = 0;

                  }

                  if(i_total5 == Integer.parseInt(sIdNumber.charAt(12)+""))

                  {

                      return true;

                  }else

                  {

                      return false;

                  }

                  }catch(IndexOutOfBoundsException ioex)

                  {

                      return false;

                  }

              }

                 

              //return flag;

          }