Remove commas and periods form a text string

Does anyone know how to remove commas and periods form a text string? I’ve done this before to remove specific words using regexReplace, but I can’t seem to get it to work with commas and periods. Thank you!

Hi @GaryStark10384, the below code will remove commas and periods as you type or paste in the text in any particular field.
You can also use this same code with an updated regex pattern to replace any characters you want (e.g. prevent text when it should be numerical).

$(document).on('knack-view-render.any', function(event, view, record) {

  // Prevent commas and periods in a short text field.
  // Replace 'field_XX' with your field key
  $('#field_XX').keyup(function() {
      this.value = this.value.replace(/[,\.]/g,'');


Thanks so much, Stephen!

1 Like

@StephenChapman this is AWESOME! I have a very similar situation. I have a {Student ID #} field and my administrators want emails to be able to go out with the first three of six digits being ***.

That being said I really want to learn how to do this and I have some questions:

  1. Does this go into a text code formula box or in the JS code area? I think it will be the JS area based on some things I have seen my team mate do.

  2. You have (‘#field_xx’) is everything within the ’ ’ the name of the field written, is the “#” part of the code, or can you use the {} with the field selection…

2b) or (if it is JS) the field names would have to be identical to the code?

Thank you thank you thank you!

@Dan3 Thanks!

I’m not sure if there was a question in your first bit, but you can achieve the concealed Student ID with a text formula field that looks like this: ***right({Student ID},3)
You can then send an email with the Student ID (Concealed) field instead of the Student ID field.

For the second part:

  1. The code I quoted above to Gary goes in the JavaScript section
  2. Text between the '' should keep the #, all you need to change is the xx to match your field key, e.g. #field_23. You will not be able to use the {fieldName} like you do in a text formula.

Hope that helps!

1 Like

You are amazing!!!