Validating cash out of Jquery Price Format

0

I'm using Jquery Price Format to format money using ,(vírgula)

To separate cents and .(ponto) to separate thousands, it looks something like this:

How can I validate this by accepting only numbers, periods, and commas?

obs: R $ prefix is not sent.

    
asked by anonymous 21.11.2016 / 05:32

2 answers

2

In PHP you can use a regex to validate the data:

$valid = preg_match('/^(\d{1,3}\.)*?(\d{1,3}),\d{2}$/','99.999,99');

The variable $valid will store the Boolean value that will inform you if the value is true, or if it is not false.

Regular Expressions

    
21.11.2016 / 11:58
2

One of the solutions is to use a pattern in the input field

follows an ex:

<input type="number" pattern="^[R$\-\s]*[\d\.]*?([\,]\d{0,2})?\s*$" />

this validates the following entries

1 => true
1,00 => true
R$1 => true
R$1000 => true
0,1 => true
1.000,00 => true
R$1.000.000 => true
5678 => true

and invalidates these others

1,001 => false
02,0 => false
22.42 => false
001 => false
192,168,1,2 => false
. => false
,55 => false
2000.000 => false

In addition, you work with the field mask to force the use of this data.

    
21.11.2016 / 11:32