There is a javascript error in your browser console

Community Alums
Not applicable

Hi,

My requirement is to auto convert the variable from lower case to upper case, also the variable should accept only '-' other than alphanumeric. I tried to attempt the code but it is showing me error. Kindly help.

 

1.PNG

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }



	var number = g_form.getValue("network_security_zone_override");
	var regEx = "^[a-zA-Z0-9\-]*$";
	if(!regEx.test(number)){
		alert('Invalid value. Only alphanumeric characters and dash allowed.');
		g_form.clearValue("network_security_zone_override");
	}

	var cap = number.toUpperCase();
	g_form.setValue("network_security_zone_override", cap);

}

 

Regards

Suman P.

 

3 REPLIES 3

piyushsain
Tera Guru
Tera Guru

Hi @Community Alums 

Use regex without quotes 

var regEx = /^[a-zA-Z0-9-]+$/;
 
Also Make Isolate script to true for the CLient Script in List view
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Amit Verma
Kilo Patron
Kilo Patron

Hi @Community Alums 

 

Please make use of below if condition to check the regex match. It should work.

 

if(!number.match('^[a-zA-Z0-9\-]*$')){
		alert('Invalid value. Only alphanumeric characters and dash allowed.');
		g_form.clearValue("network_security_zone_override");	
	}

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Unique45
Mega Sage

Hello @Community Alums ,

Please add below code in the client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	var regEx = /^[a-zA-Z0-9-]*$/;
	if(!regEx.test(newValue)){
		alert('Invalid value. Only alphanumeric characters and dash allowed.');
		g_form.clearValue("network_security_zone_override");
	}
	else{
		g_form.setValue("network_security_zone_override",newValue.toUpperCase() );
    }
	
}

 

 

Please mark correct/helpful if this helps you!