There is a javascript error in your browser console

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 10:34 PM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 10:46 PM - edited 01-10-2024 10:53 PM
Hi @Community Alums
Use regex without quotes
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 11:25 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 12:00 AM
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() );
}
}