- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2019 10:54 PM
Hi Everyone,
I hope you all are doing good. 🙂
Mandatory fields are accepting spaces, without having to enter any character. I need a script for checking single or multiple space too. I took reference from community and tried a code but it is working for a single space. If user will add multiple spaces so this code won't work. The code is given below:
Wrote an onChange Client Script for the field
if (g_form.getValue('u_recommended_ltf') == ' '){
alert("Please fill Analysis Output field ");
g_form.setValue('u_recommended_ltf', '');
}
Could you please help me out for this script.
Kind Regards,
Swati
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2019 11:04 PM
var d = g_form.getValue('u_recommended_ltf');
d = d.replace(/\s/g, "");
if (d==""){
alert("Please fill Analysis Output field ");
g_form.setValue('u_recommended_ltf', '');
}
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 08:21 AM
Hi Swati, Good that you found the solution. By the way, I have updated my suggested coding and is working now. If u free, you can have a looks so that you have another alternative in future.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading){ //|| newValue === ''){
return;
}
var regex = new RegExp("^(?!\s*$).");
if(!regex.test(newValue)){
alert("Please fill Analysis Output field ");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2019 11:39 PM
HI Swathi,
Key is whether it is just whitespace or double space alone that you would want to be stopped?
I would recommend you to have a comprehensive validation code to ensure only valid content is added to the mandatory field.
Some good to have validations
1)Content should not start with space/double space (use trim() to remove leading and trailing spaces)
2)Content should start with only alpha numerals. and so on.
Put all that patterns into a script include and can be reused anywhere , anytime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 05:57 AM
Thanks Mahira for the information 🙂