Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

How to check digit

Avatar

Level 2

If Digit(Curency) is entered in field the value will be added. If not digit, just alphabate not added to the total field.

Text1 value = "A"

Text2 value = "$2.00"

Text3 value = "$4.70"

Total =Text2 value+Text3 value.

How to check filed value contains digit?


2 Replies

Avatar

Level 10

Hi,

One way of parsing a currency amount is to add a hidden decimal field, with the display patterns you need, then assign the string with currency symbol to the formattedValue.  If it matches the pattern then the rawValue will be set just as a straight number.

So try;

function parseCurrency(string)

{

    var result = 0;

    if (string !== null && string !== undefined)

    {

        DecimalField1.rawValue = null;

        DecimalField1.formattedValue = string;

        if (!DecimalField1.isNull)

        {

            result = parseFloat(DecimalField1.rawValue);

        }

    }

    return result;

}

var Total = parseCurrency(TextField1.rawValue);

Total += parseCurrency(TextField2.rawValue);

Total += parseCurrency(TextField3.rawValue);

With a display pattern of num{$zzz,zzz,zz9.88}|num{$zzzzzzzz9.88} for DecimalField1

Regards

Bruce

Avatar

Level 2

Hi Bruce

After a long time you are in this forum. Hope you are well. Regularly I review your post as you provide powefull and unique solution.

Thanks for your reply.