Is there a quick and easy way to confirm if an input currency is valid?

Is there a quick and easy way to confirm if an input currency is valid?

  

I want to check an Input has been entered correctly as a currency, is there an easy way to do this rather than having to do things like use Index to check for more than one decimal point for example?

Also if I use an Input with type Number, it only allows an Integer to be input, whereas I want to allow a Decimal, so that forces me to use a text type Input which means checking for letters as well as other invalid characters and I can't see a quick way to do that.

I'm sure there must be an easier way to do this, like some kind of decimal/currency Input widget or inbuilt function but I can't find anything?

Hi,

You could use this extension to force the user to input a valid number, and then this one to make sure it's actually valid.



Brilliant thanks, I'll check them out!

Solution

Hello Sienna.

Besides using a MASK, what you want is to validate your input.
Both Client & Server as well as Server validations will perform two basic validations automatically: Mandatory fields and Data Type.

So, if your user types something that can't be converted to the type of the variable bounded to your input, the input is marked as invalid (Valid property set to False), and if the input is inside a Form, the Form.Valid property is also set to False.

So, ou can than alert the user about the mistake.

Regarding the definition of the Input type to Number, as far as I can remember, to allow it to receive decimals, you need to add the attribute step="any". You can do this through the Extended Properties, tag step, value "any". 

This will not prevent the user of typing letter, for example, but will make the browser do not accept the value if you try to submit (afaik).

Hope this helps.

Cheers. 

Solution

Sorry only just got around to looking at these.  The Custom Masks is not compatible with v11 that I'm running.  I'm not sure the other one (Validate Regular Expression Dynamically) is meant to be either but it installed ok.  However I have no idea how to use this.  I have added it as a dependency and can see that it's added 2 static entities, but I'm unsure how to utilise it.  I was expecting a web block or something that I could add as a widget or a server action that I could call, but it doesn't appear to work that way.  (Sorry if a rookie questions but I'm new to Outsystems.)

Eduardo Jauch wrote:

Hello Sienna.

Besides using a MASK, what you want is to validate your input.
Both Client & Server as well as Server validations will perform two basic validations automatically: Mandatory fields and Data Type.

So, if your user types something that can't be converted to the type of the variable bounded to your input, the input is marked as invalid (Valid property set to False), and if the input is inside a Form, the Form.Valid property is also set to False.

So, ou can than alert the user about the mistake.

Regarding the definition of the Input type to Number, as far as I can remember, to allow it to receive decimals, you need to add the attribute step="any". You can do this through the Extended Properties, tag step, value "any". 

This will not prevent the user of typing letter, for example, but will make the browser do not accept the value if you try to submit (afaik).

Hope this helps.

Cheers. 

I had mistakenly presumed I needed to enter a string (text data type) variable for an input text box but have now changed it to a decimal.  I couldn't find an attribute step (I'm running v11) but it appears to work fine now anyway just by changing the variable type input.  Thanks!