Question


Veteran Careers First
US
Last activity: 21 Nov 2018 15:50 EST
Function/expression
I am attempting to write an expression/function using expression builder in a when rule to evaluate to true only if number is integer or decimal. Or Non Alpha.
Example:
@isNumber(.property)
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution


Veteran Careers First
US
I tried this and it appears to work great.
try {
new BigDecimal(input);
} catch (NumberFormatException e) {
return false;
}
return true;


TechMahindra
IN
Hi HenryA80,
Create a simple new function to achieve this.
FunctionName: IsNumericOnly
Parameters: input as String
Return output: boolean
Function Code:
java.util.regex.Pattern p = java.util.regex.Pattern.compile("^[0-9]\d*(\.\d+)?$");
java.util.regex.Matcher m = p.matcher(input);
return m.matches();


Veteran Careers First
US
Function are difficult for me.
Would you be so kind to provide screenshots.


TechMahindra
IN
Please follow following steps.


TechMahindra
IN
PFA screenshots to create function.


Veteran Careers First
US
Thanks.
I guess I also need to create a Library rule.


Veteran Careers First
US
I created Library and Function.
But I do not see it in the expression builder.
Is there another step....


Veteran Careers First
US
Vsasikumar,
It is working great but does not allow negative numbers.
How can we make this adjustment.


Pegasystems Inc.
IN
You can just change the expression from "^[0-9]\d*(\.\d+)?$" to "^[+-0-9]\d*(\.\d+)?$"
Let us know if this helps :)


Veteran Careers First
US
ok
I will try that.
Thanks!


Veteran Careers First
US
I am still having trouble.
Attached are my new results.
Accepted Solution


Veteran Careers First
US
I tried this and it appears to work great.
try {
new BigDecimal(input);
} catch (NumberFormatException e) {
return false;
}
return true;


EvonSys India Pvt Ltd
AU
Just try property type as an integer and tried the given function @IsInteger and it's for your requirement


Veteran Careers First
US
Property Type is currently decimal.I can't change the property to integer because it needs to accept decimals.
@IsInteger does not allow decimals


EvonSys India Pvt Ltd
AU
Create a function and try with a regular expression which they discussed as above members


Veteran Careers First
US
I created Library and Function.
But I do not see it in the expression builder.
Is there another step....