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

Validating a numeric field

Bibhu_Bikash_Na
Level 9
Level 9

Hello All,

I am using a form where the price of items will be fetched from an embedded xml. The price written in the xml as "9,27", "11,80" . There is a column called qunatity and a column called retail price. After the price has been by the xml the user will simply enter the quantity and the retail price will calculate it by multiplying with the qunatity. So I need a proper validation for these fields price and retail price so that the '$' symbol will also come in the beginning.


Just a reminder " The prices written as "6,80" , "11,90" like this .

Thanks.

Bibhu.

13 Replies
_Nith_
Level 10
Level 10

Regular Expressions are the most appropriate validation method for this requirements.

Nith

Bibhu_Bikash_Na
Level 9
Level 9

Hello,

Would you please kindly suggest how to validate this one ?

Thanks.

Bibhu.

Steve_L_Walker
Level 10
Level 10

Is this what you are after?

Untitled1.png

Untitled.png

// form1.page1.subform1.table.row[0].retailPrice::calculate - (JavaScript, client)

if (quantity.isNull) {

  this.rawValue = null;

}

else {

  var comma = /\,/g;

  var priceStr = price.rawValue;

  priceStr = priceStr.replace(comma,".");

  var priceNum = parseFloat(priceStr);

  var retailPriceNum = (priceNum * quantity.rawValue).toFixed(2);

  var retailPriceStr = retailPriceNum.toString();

  this.rawValue = "$" + retailPriceStr.replace(".",",");

}

Steve

Bibhu_Bikash_Na
Level 9
Level 9

Hello Steve,

Thanks for the example. This is what I need. But I would like to see a '$' symbol before the price as well. How to do it ?

Thanks.

Bibhu.

maheshsharmajee
Level 1
Level 1

Buddy I couldn't understand. Where you want to add Symbol $? Plz would you explain it?

Bibhu_Bikash_Na
Level 9
Level 9

Hello Mahesh,

As the price is in dollar so I would like to add the dollar symbol before it as it shows in the final retail price.

Thanks.

Bibhu.

Bibhu_Bikash_Na
Level 9
Level 9

Hello Steve,

Would you please say what changes you have made to the previous form ?

Thanks.

Bibhu.

Bibhu_Bikash_Na
Level 9
Level 9

Hello Steve,

When I apply your concept to my form . I found the price validation is failing. Why so ? Could you please explain ?

Thanks.

Bibhu.

Bibhu_Bikash_Na
Level 9
Level 9

Hello Steve,

One more thing I would like to add. Somehow I manage with the price validation. Now my problem is :

1. The '$' is not getting appended  to its value.

2. In the Total price it's only multiplying the last tto digits after the comma.

Thanks.

Bibhu.

Steve_L_Walker
Level 10
Level 10

Two changes. One, I added script to the price initalize event to add the dollar sign.

// form1.page1.subform1.table.row[0].price::initialize - (JavaScript, client)

if (this.isNull) {

  this.rawValue = null;

}

else {

  this.rawValue = "$" + this.rawValue;

}

Two, I added priceStr = priceStr.substring(1,priceStr.length); to the calculate event on the retailPrice to remove the dollar sign.

// form1.page1.subform1.table.row[0].retailPrice::calculate - (JavaScript, client)

if (quantity.isNull) {

  this.rawValue = null;

}

else {

  var comma = /\,/g;

  var priceStr = price.rawValue;

  priceStr = priceStr.substring(1,priceStr.length);

  priceStr = priceStr.replace(comma,".");

  var priceNum = parseFloat(priceStr);

  var retailPriceNum = (priceNum * quantity.rawValue).toFixed(2);

  var retailPriceStr = retailPriceNum.toString();

  this.rawValue = "$" + retailPriceStr.replace(".",",");

}

Regarding the total price, do you have display or validation patterns defined on the object? If you send me the form I can take a look stwalker.adobe@gmail.com

Steve

Bibhu_Bikash_Na
Level 9
Level 9

Hello Steve,

I have not defined any validation pattern in the total column. More over in the price column it's not showing any $ sign . What can be the problem?One thing I would like to add here. If i manually type some dataof the format "$9,27" and then multiply it to get the total price everything works fine. But the moment I import the xml to embed all the price data it's showing the above problem . I am totally confused.

Thanks.

Bibhu.

Steve_L_Walker
Level 10
Level 10

If you send me the form I'd be happy to take a look stwalker.adobe@gmail.com

Steve