How to validate a field with the luhnCheck

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
yahya
Posts: 77
Joined: Sat Jul 16, 2011 6:00 am
Location: South Africa
Contact:

How to validate a field with the luhnCheck

Post by yahya »

How would a person go about implenting a validation on a field using the luhnCheck?

function luhnCheck(number) {
number = String(number);
let sum = parseInt(number.charAt(number.length - 1));
for (let i = 0; i < number.length - 1; i++) {
let value = parseInt(number.charAt(i));
if (i % 2 === 0) {
value *= 2;
}
if (value > 9) {
value -= 9;
}
sum += value;
}
return sum % 10 === 0;
}
AwareIM Developer edition. Version 8.5 (Build 2827) running on Windows Server 2012 R2 Standard
himanshu
Posts: 722
Joined: Thu Jun 19, 2008 6:24 am
Location: India
Contact:

Re: How to validate a field with the luhnCheck

Post by himanshu »

You can do this with Custom JS or function (build on Java).
From,
Himanshu Jain


AwareIM Consultant (since version 4.0)
OS: Windows 10.0, Mac
DB: MYSQL, MSSQL
yahya
Posts: 77
Joined: Sat Jul 16, 2011 6:00 am
Location: South Africa
Contact:

Re: How to validate a field with the luhnCheck

Post by yahya »

How do a reference the check to the javascript?
AwareIM Developer edition. Version 8.5 (Build 2827) running on Windows Server 2012 R2 Standard
hpl123
Posts: 2579
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: How to validate a field with the luhnCheck

Post by hpl123 »

yahya wrote: Wed Oct 21, 2020 11:23 am How do a reference the check to the javascript?
Search the forum for exec_script and you will find many different examples of this in use. If you figure it out, please share the solution as a tip. Thanks
Henrik (V8 Developer Ed. - Windows)
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: How to validate a field with the luhnCheck

Post by PointsWell »

LuhnCheck is part of the commons validator package. https://commons.apache.org/proper/commo ... Digit.html

That's the good news, the bad news is that the version of commons validator that has been implemented in Aware does not include it.

But! I have implemented elements of commons validator into my own Java plug in so it is super easy to do https://awareim.com/forum/viewtopic.php?f=4&t=11751

IANAJP* and I managed to do it pretty much first time with the aid of the How to YouTube videos
https://youtu.be/-TSpGdb-oWg
https://youtu.be/yGEyyffgoLo
https://youtu.be/RiP845aGzws

* I Am Not A Java Programmer
himanshu
Posts: 722
Joined: Thu Jun 19, 2008 6:24 am
Location: India
Contact:

Re: How to validate a field with the luhnCheck

Post by himanshu »

If you need a function built on Java, you can PM me.
From,
Himanshu Jain


AwareIM Consultant (since version 4.0)
OS: Windows 10.0, Mac
DB: MYSQL, MSSQL
Post Reply