0

I have operator and value as string. When my operator equal to '>' or '<' then i need to ensure the value of the string is numeric or Decimal so it can wrk for both. But i see only isNumeric() ? Any idea

String operator = '<';
String value = '3.14';
if(operator.equals('<') && operator.isNumeric() || //Check operator isDecimal)
{
  //Process criteria
}

I am thinking in such a way below

 try{

    Double value = Decimal.valueOf('1234a');
}
catch(exception ex)
{
    system.debug('Not a number');
    //process further
}

But didn't feel ts opt. Suggest me!

1

Finally end up with the regex as below,

public Boolean isValidIntegerOrDecimal(String value) {
    String amtRegEx = '\\d+(\\.\\d+)?';
    Pattern MyPattern = Pattern.compile(amtRegEx);
    Matcher MyMatcher = MyPattern.matcher(value);
    Boolean flag = MyMatcher.matches();
    return flag; 
}

   system.debug(isValidIntegerOrDecimal('0.01'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.