function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shuhbam SinhaShuhbam Sinha 

How to remove comma from <lightning-input-field > in lwc

Hello Everyone,
I need to remove comma from  <lightning-input-field > in lwc. So what is happening is  there is one number data type field that I am using in my record edit form but if i enter a number Salesforce automatically adds comma. So is there any way to remove that. I found one article for <lightning-input> where we can use any reg ex (pattern="^(0|[1-9][0-9]*)$" )pattern to remove commat but <lightning-input-field > does not support this reg ex pattern. How can i do the same thing with  <lightning-input-field > . Anyone has idea on the same, please suggest any way. Thanks in advance.

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Shuhbam,

Do you mean to remove commas while user is inputting right? Or do you mean to show to user in UI on view ?

Thanks,
 
Shuhbam SinhaShuhbam Sinha
Hello Sai,
This issue is happening for both lightning input field as well as lightning output field.So basically I need a workaround to remove comma from both the places .
Sai PraveenSai Praveen (Salesforce Developers) 
HI Shuhbam,

If that is lightning-input you can use onchange event and remove the commas in js file as below.
 
<lightning-input-field onchange={removeCommaFromNumber} field-name="Your_Field_Name"></lightning-input-field>
 
removeCommaFromNumber(event) {
  let input = event.target.value;
  if (typeof input === 'string') {
    input = input.replace(/,/g, ''); 
    event.target.value = input;
  }
}

If this solution helps, Please mark it as best answer.

Thanks,
Shuhbam SinhaShuhbam Sinha
Hello Sai,
I already tried this approach but it was not working .
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Shubham,

Do you mean it is not working in input. When user gives value it is appending with comma before saving?

Thanks,
 
Shuhbam SinhaShuhbam Sinha
Yes Sai