ChildOfCode


Code, Maker, Robotic, Open Source. Knowledge Bases


Java Check Input integer

Java

@Kroll.method
    public String InputCheck(String value1 , String value2)
    {
        String inputType= "";
        String [] numbers = {value1, value2};


         for(String x : numbers ) {
             try{
                int checkInput = Integer.parseInt(x);
                inputType = "Number";
            }catch (NumberFormatException ex) {
                //handle exception here
                inputType = "No Number!";
                break;
            }

          }

         if(inputType == "Number"){

             int Intvalue1 = Integer.parseInt(value1); 
             int Intvalue2 = Integer.parseInt(value2); 
             System.out.println(Intvalue1+Intvalue2); //[DEBUG]
             String theReturn = Integer.toString(Intvalue1+Intvalue2);
             return theReturn;
         }else{
             return inputType;
         }

    }

JavaScirpt

Ti.API.info("Input Test = "+calculatorModule.InputCheck("1000","123"));