Let me share the code to validate the price (for example) format on input field.
It checks whether the input is number and followed by exactly two decimal digits.
Such as
1.121 false
1.20 true
.20 false
0.20 true
0.2 false
12 true (no decimals)
There was a request for this validation on the forum and I guess it might a snippet usefull for others too.
The code to be set on Blur on Javascript validation of element.
Try this code:
var str = this.get('value');
var re1=/^\s*-?\d+(\.\d{2,2})?\s*$/;
var result1=re1.test(str);
if ( result1 === false ) {
if (!confirm("You have to use number with 2 decimal digits such as 1.15 !")) {
this.update('wrong number format');
}
}
It checks whether the input is number and followed by exactly two decimal digits.
Such as
1.121 false
1.20 true
.20 false
0.20 true
0.2 false
12 true (no decimals)
There was a request for this validation on the forum and I guess it might a snippet usefull for others too.
The code to be set on Blur on Javascript validation of element.
Try this code:
var str = this.get('value');
var re1=/^\s*-?\d+(\.\d{2,2})?\s*$/;
var result1=re1.test(str);
if ( result1 === false ) {
if (!confirm("You have to use number with 2 decimal digits such as 1.15 !")) {
this.update('wrong number format');
}
}