- 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-28-2019 11:03 PM
Hello Swati,
Add bewlo code in your script so it wont accept the spaces.
var userText = g_form.getValue('u_recommended_ltf');
userText = userText.replace(/^\s+/, '').replace(/\s+$/, '');
if (userText === '') {
// text was all whitespace
} else {
// text has real content, now free of leading/trailing whitespace
}
Explanation:
/^\s+|\s+$/g searches for whitespace from either the beginning or the end of the string. The expression can be split into two parts, ^\s+ and \s+$ which are separated by | (OR). The first part starts from the beginning of the string (^) and includes as many whitespace characters it can (\s+). The second part does the same but in reverse and for the end using the dollar sign ($).
Note that \s matches spaces, tabs and line breaks.
The /g part at the end enables global searching, which allows multiple replacements (eg. not just the beginning, but the end of the string also
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 05:52 AM
Hi Abhishek,
Thanks for the reply and explanation!
Regarding the below line why r u using 3 times '=' ?
if (userText === '')
Many Thanks,
Swati
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 05:54 AM
Hello Swati,
JavaScript has both strict and type–converting comparisons. A strict comparison (e.g., === ) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. == ) converts the operands to the same type before making the comparison.
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2019 11:03 PM
Hi Swathi,
Can you please try the below code,
var rem = g_form.getValue('u_recommended_ltf');
if (!rem){
alert("Please fill Analysis Output field ");
g_form.setValue('u_recommended_ltf', '');
}
If my reply has helped you,Kindly click the Helpful button.
If my reply is the answer you were looking for, Kindly click the Accepted Solution button.
Thanks,
Priya