The CreatorCon Call for Content is officially open! Get started here.

Mandatory fields are accepting spaces, without having to enter any character.

SNOW32
Giga Expert

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', '');

}
 find_real_file.png

Could you please help me out for this script. 

 Kind Regards,

Swati

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage
Mega Sage

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', '');

}

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

12 REPLIES 12

Thanks Priya!  🙂

Your reply is helpful but the answer i was looking for is already given by Ahmmed.

Ahmmed Ali
Mega Sage
Mega Sage

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', '');

}

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Thanks Ahmmed!

weikiat_guaz
Giga Expert

You can use REGEX. So next time you have flexibility to add more validation when needed.

Below is example to check white space & blank. You can refer to this for REGEX https://www.regextester.com/98264

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {
      return;
   }


   var regex = new RegExp("^(?!\s*$).");
   if(!regex.test(newValue)){
     alert('No content');
}


}

Thanks Weikiat.G!

I got the solution already