Question
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
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
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
I tried this and it appears to work great.
try {
new BigDecimal(input);
} catch (NumberFormatException e) {
return false;
}
return true;
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
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();
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
Function are difficult for me.
Would you be so kind to provide screenshots.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
TechMahindra
IN
Please follow following steps.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
TechMahindra
IN
PFA screenshots to create function.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
Thanks.
I guess I also need to create a Library rule.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
I created Library and Function.
But I do not see it in the expression builder.
Is there another step....
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
Vsasikumar,
It is working great but does not allow negative numbers.
How can we make this adjustment.
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/1689977000/ca5d61dc-47bd-406c-8ea6-9d6a790a4f7e.jpg?itok=O3xagdnP)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/1689977000/ca5d61dc-47bd-406c-8ea6-9d6a790a4f7e.jpg?itok=O3xagdnP)
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 :)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
ok
I will try that.
Thanks!
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
I am still having trouble.
Attached are my new results.
Accepted Solution
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
I tried this and it appears to work great.
try {
new BigDecimal(input);
} catch (NumberFormatException e) {
return false;
}
return true;
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
EvonSys India Pvt Ltd
AU
Just try property type as an integer and tried the given function @IsInteger and it's for your requirement
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
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
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
EvonSys India Pvt Ltd
AU
Create a function and try with a regular expression which they discussed as above members
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Veteran Careers First
US
I created Library and Function.
But I do not see it in the expression builder.
Is there another step....