isNumeric?

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

isNumeric?

#1

Postby Jez » Fri Mar 04, 2016 9:51 am

This feels like it should be a really easy one...

I've a dual purpose, form field that I want the user to enter either a DOB or an age in. So the field is set as a Char and I'm validating the input in fpl to determine if they've entered an age or DOB.

Where the field is 1 or 2 characters long, I want to check that they're numeric (an age) so I can error back to the user if not.

But I can't seem to find a 'isNumeric' function or similar in fpl? Am I missing it or any other ideas on how I can check in fpl if the Chars are numeric?
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#2

Postby Steve James » Fri Mar 04, 2016 10:05 am

Hi, try the following in JS, you can call a JS function from FPL.

Code: Select all

isNaN(value);
It returns a boolean.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Fri Mar 04, 2016 10:22 am

It's a bit harder in FPL, but you could use this - it will only return true for integers which seems to be what you need.

Code: Select all

if [tostring(javaMethod('org.apache.commons.lang.StringUtils.isNumeric', FIELD1)) = 'true']
0 x

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

#4

Postby Jez » Fri Mar 04, 2016 11:11 am

Fantastic! Thanks both for two great answers - I've tested both and they both work well.

I created a JS script with Steve's isNAN code and called it using callscript from my fpl script. This works nicely, setting another field on my form with the isNAN result which I can interpret in the remaining fpl.

However, unless there are any potential gotcha's, I'll probably go with Jon's single line of code from fpl. I hadn't realised you could call javaMethod's this way from fpl.

Every day's a learning day :D
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#5

Postby Steve James » Fri Mar 04, 2016 11:56 am

Yes Jez, I didn't know it is possible to call javaMethods within FPL.

That said we've eventually managed to get all form writers onto JS as it is so much more powerful. We've not looked back!
We've still got hundreds of FPL scripts and they still work fine. If we need to tweak an FPL we do, if the FPL needs significant modifications we just port into JS (mostly this is pretty simple).

Another option in FPL (my FPL is pretty rusty now).
There's an FPL function called 'regex' - it's not documented so I assume Ebase supplied it (?)

Code: Select all

char chk = VALUETOCHECK;
chk = regex('^[0-9]*$',chk);
It returns true, failed or an error message.
0 x


Who is online

Users browsing this forum: No registered users and 19 guests