forked from MapComplete/MapComplete
31 lines
842 B
TypeScript
31 lines
842 B
TypeScript
import { Translation } from "../../i18n/Translation"
|
|
import Translations from "../../i18n/Translations"
|
|
import FloatValidator from "./FloatValidator"
|
|
|
|
export default class PFloatValidator extends FloatValidator {
|
|
constructor() {
|
|
super("pfloat", "A positive decimal number or zero")
|
|
}
|
|
|
|
isValid(str: string) {
|
|
if (!super.isValid(str)) {
|
|
return false
|
|
}
|
|
if (!FloatValidator.formattingHasComma) {
|
|
str = str.replace(",", ".")
|
|
}
|
|
const n = Number(str)
|
|
return n >= 0
|
|
}
|
|
|
|
getFeedback(s: string): Translation {
|
|
const spr = super.getFeedback(s)
|
|
if (spr !== undefined) {
|
|
return spr
|
|
}
|
|
if (Number(s) < 0) {
|
|
return Translations.t.validation.nat.mustBePositive
|
|
}
|
|
return undefined
|
|
}
|
|
}
|