How can I restrict special characters in string field in catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 03:06 PM
I don't want any special character to be added in string field in service catalog item.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 03:42 PM
Hello,
Please check if this helps.
Try this onchange catalog client script.
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
var pattern = /^[0-9a-zA-Z]*$/;
if(!pattern.test(newValue))
{
alert('type your appropriate comments here');
g_form.setValue('variable_name', ''); // adjust field name accordingly if you want to blank it out.
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 05:43 PM
Hello Shishir,
Following is the script which I am currently using
function onSubmit() {
//Type appropriate comment here, and begin script below
var alpha = new RegExp("^[a-zA-Z0-9]*$");
var BusinessCase=g_form.getValue('justification');
//alert("value"+BusinessCase);
var res=alpha.test(BusinessCase);
if (!res) {
// g_form.showFieldMsg('justification', 'Invalid input', 'error');
alert ("Special Charecters are not allowed on Justification");
return false;
}
return;
}
This script do not allows "Space" in the string field
Could you please tell me what changes needs to be done in current script in order to run this if statement containes spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 11:56 AM
Dear All,
I have finalised my script as follows
this works for restricting special character as well as allowing spaces in between
function onSubmit() {
// Type appropriate comment here, and begin script below
//var alpha = new RegExp("^[a-zA-Z0-9]*$");
var alpha = /^[\s0-9a-zA-Z]*$/;
var BusinessCase=g_form.getValue('justification');
//alert("value"+BusinessCase);
var res=alpha.test(BusinessCase);
if (!res) {
//g_form.showFieldMsg('justification', 'Invalid input', 'error');
alert ("Special Charecters are not allowed on Business Case / Justification field");
return false;
}
return;
}
Regards,
Surendra Deshmukh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 12:17 PM
Thank you for the update, i missed to see your earlier response.