diff --git a/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts b/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts index 9eede0aa2b7..cbf6b2ecf1c 100644 --- a/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts +++ b/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts @@ -292,6 +292,9 @@ describe( agHelper.ClearNType(locators._input, "100"); agHelper.ValidateToastMessage("Value Changed"); + agHelper.WaitUntilToastDisappear("Value Changed"); + agHelper.ClearNType(locators._input, "a"); + cy.get(locators._toastMsg).should("not.exist"); // onFocus propPane.SelectPlatformFunction("onFocus", "Show alert"); diff --git a/app/client/src/widgets/PhoneInputWidget/widget/index.tsx b/app/client/src/widgets/PhoneInputWidget/widget/index.tsx index 6fc16f1570e..7b215fc4d87 100644 --- a/app/client/src/widgets/PhoneInputWidget/widget/index.tsx +++ b/app/client/src/widgets/PhoneInputWidget/widget/index.tsx @@ -411,13 +411,18 @@ class PhoneInputWidget extends BaseInputWidget< "value", parseIncompletePhoneNumber(formattedValue), ); - this.props.updateWidgetMetaProperty("text", formattedValue, { - triggerPropertyName: "onTextChanged", - dynamicString: this.props.onTextChanged, - event: { - type: EventType.ON_TEXT_CHANGE, - }, - }); + // This regular expression validates that the input: + // - Does not start with a whitespace character + // - Contains only digits, spaces, parentheses, plus, and minus symbols + if (/^(?!\s)[\d\s()+-]*$/.test(value)) { + this.props.updateWidgetMetaProperty("text", formattedValue, { + triggerPropertyName: "onTextChanged", + dynamicString: this.props.onTextChanged, + event: { + type: EventType.ON_TEXT_CHANGE, + }, + }); + } if (!this.props.isDirty) { this.props.updateWidgetMetaProperty("isDirty", true); }