how to validate string value as integer?

0
Hi all,   I’m working on an application where i.m retrieving data from database on a page.  I have  a string attribute defined in API to which I have to validate as it should not accept string value (Accept only integer value greater than 0). For that I tried                                          parseInteger(string attribute)>0   but it is giving me an admin error. Please help me with this.
asked
4 answers
2

parseInteger(string attribute)>0 will return an error if the string attribute cannot be parsed to int. so you just need to create an error handling flow, look at this : 

https://docs.mendix.com/refguide/error-handling-in-microflows/

 

a second option would be to use a regex with the function ismatch()

answered
0

 

Hi Chaitali Gangane,

 

you can check with the below regex expression

  isMatch($Entity/attribute, '^([0-9]+)$')

 

Hope it helps you!

answered
0

Hi Chaitali,

 

You are on the track, but you also have to customize the error handling of the action parsing the string in order to catch the exception, and then apply an error handler activity flow as Yehoshua already explained.

 

Best,

Istvan

answered
0

It sounds like the string needs to start with a digit that isn’t zero, and be followed by zero or more digits. We can look for this using a regular expression and isMatch.
 

isMatch($Entity/attribute, '^[1-9][0-9]*$')


If this passes you can then use the parseInteger method to convert the string to an integer.
 

parseInteger($Entity/attribute)


I hope this helps.

answered