Hi Zoran,
I made with custom JS. Found it to be the easiest way.
On input “OnChange” event I just trigger the following code, which checks if the input value contains the target phrase “IP” and if it does, then removes the phrase and returns the rest of the input.
I also have “was_changed” parameter which is not necessary. I just use it to be aware if the code has made any changes to the input value.
const input = variables['a78ec4fc-4112-412c-aeda-d800e356f73c'];
let value = input;
let was_changed = false;
if (typeof input === 'string') {
const newValue = input.replace(/^IP[\s\u00A0\u2000-\u200B\u202F\u205F\u3000]*/i, '');
if (newValue !== input) {
value = newValue;
was_changed = true;
}
}
return {
value: value,
was_changed: was_changed
};
1 Like
you need to use “custom JavaScript” action:
As for the proper code you just can ask Weweb AI or another LLM to write a code for you according to your task. Like this:
function cleanMacedonianString(myString) {
const macedonianLetters = 'абвгдѓежзѕијклљмнњопрстќуфхцчџшАБВГДЃЕЖЗЅИЈКЛЉМНЊОПРСТЌУФХЦЧЏШ';
// Use regex to match all characters not in the allowed set and remove them
const regex = new RegExp(`[^${macedonianLetters}]`, 'g');
return myString.replace(regex, '');
}
let myString = "Здраво, World! 123";
myString = cleanMacedonianString(myString);
console.log(myString); // Outputs: "Здраво"
Thank you Batik
This is how i have made:
const input = document.getElementById(“ReceiverName”);
const allowedRegex = /*$/;
const value = input.value;
if (!allowedRegex.test(value)) {
setTimeout(() => {
input.value = value.replace(/[^АБВГДЃЕЖЗЅИЈКЛЉМНЊОПРСТЌУФХЦЧЏШабвгдѓежзѕијклљмнњопрстќуфхцчџш]/g, ‘’);
}, 100);
variables[‘invalidInput’] = true;
} else {
variables[‘invalidInput’] = false;
}
And it works but have one problem. From time to time it not delete wrong characters. Probably this need to be done in a way to check keypress or keydown and if charachter is not allowed to cancel entering it in input. I have try allot of thing also with help of ChatGPT and WeWeb Ai but without help. Also dont know how to prevent pasting in input.
Try to activate debounce =200ms or 300 ms in the settings of the input field. . That should solve the problem.
I assume that the code just doesn’t have enough time to execute in the case of fast typing. Debounce should help.