From 58b759bd6a9acab01cc20a3376a1cbee796fd739 Mon Sep 17 00:00:00 2001 From: MartinT <44962077+MartinTuroci@users.noreply.github.com> Date: Mon, 5 Oct 2020 09:06:24 +0200 Subject: [PATCH] fix: input widget number validation #768 (#917) --- app/client/src/widgets/InputWidget.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/client/src/widgets/InputWidget.tsx b/app/client/src/widgets/InputWidget.tsx index 05d791fcc6..9fbd074f33 100644 --- a/app/client/src/widgets/InputWidget.tsx +++ b/app/client/src/widgets/InputWidget.tsx @@ -61,12 +61,15 @@ class InputWidget extends BaseWidget { return { isValid: `{{ function(){ - const isEmailType = this.inputType === "EMAIL"; - if(isEmailType) { + if (this.inputType === "EMAIL") { const emailRegex = new RegExp(/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$/); return emailRegex.test(this.text); - } else if(this.isRequired) { - if(this.text && this.text.length > 0) { + } + else if (this.inputType === "NUMBER") { + return !isNaN(this.text) + } + else if (this.isRequired) { + if(this.text && this.text.length) { if(this.regex) { return new RegExp(this.regex).test(this.text) } else { @@ -75,7 +78,7 @@ class InputWidget extends BaseWidget { } else { return false; } - } if(this.regex) { + } if (this.regex) { return new RegExp(this.regex).test(this.text) } else { return true;