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

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 ");
   }
   
}

Mahira
Tera Guru

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.

 

 

Thanks Mahira for the information 🙂