How to remove special characters of input field?

In Item Doc-type I have a custom field(item_search). I want to fetch the item_code value to this custom field but I want to remove special characters in that value.

I tried writing custom script, Its fetching the value but removing the special characters not worked.

so, I tried changing the code in Item.js file

item_code: function(frm) {
if(!frm.doc.item_name)
frm.set_value(“item_name”, frm.doc.item_code);
if(!frm.doc.item_search)
frm.set_value(“item_search”, frm.doc.item_code.replace(/[^A-Z0-9]/ig, “”);
if(!frm.doc.description)
frm.set_value(“description”, frm.doc.item_code);
},

Which is the best way to achieve this? Custom script or changing the code?

Custom Script worked
so here is the code to remove the special characters

frappe.ui.form.on("Item", {
  item_code: function(frm) {
	var nxfield1 = frm.doc.item_code;
	var nxfield2 = nxfield1.replace(/[^a-zA-Z ]/g, "");
	if(!frm.doc.item_search)
	frm.set_value("item_search", nxfield2);

  }
});
2 Likes