Spaces are auto trimmed in Single Line text variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 01:35 AM
We have requirement where if a user enters any space or special characters in "Single Line Text variable" then we need to show a alert message saying "Spaces and Special Characters not Allowed."
However I am able to handle the special characters and inBetween spaces. The issue is with Leading and Trailing spaces. It seems the "Single Line Text variable" ignores the leading and trailing spaces or there is backend TRIM() running on it hence I am not able to deal with it.
Anyone with any Idea to Cop with above issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 02:22 AM
What's your script looking like?
I tried a quick one on my pdi with this and it seems to work:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var regex = /^[^\s].*[^\s]$|^[^\s]$/;
if (!regex.test(newValue) || /[^a-zA-Z0-9]/.test(newValue)) {
alert('Spaces and Special Characters are not allowed.');
}
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 05:51 AM
Hi @Anant Samaiya ,
You can use OnChange client script on Requested Item table for the particular field which you are looking at and apply this script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Regular expression to match only numbers and alphabets
var regex = /^[A-Za-z0-9]+$/;
if (!newValue.match(regex)) {
alert("Please enter only numbers and alphabets.");
g_form.setValue(control.name, oldValue); // Reset the field value to the old value
}
}
Mark my Answer Helpful or Accept Solution if it resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:21 AM
Hi @Anant Samaiya ,
You can use OnChange client script for that particular field which you are looking-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Regular expression to match only numbers and alphabets
var regex = /^[A-Za-z0-9]+$/;
if (!newValue.match(regex)) {
alert("Please enter only numbers and alphabets.");
g_form.setValue(control.name, oldValue); // Reset the field value to the old value, if you need
}
}
Mark my Answer Helpful or Accept Solution if it resolves your issue.