Disallow Special Characters to enter in text field

Thummala_Murthy
Kilo Contributor

Hi Friends,
I need help in scripting to "Disallow Special Characters to enter in text field".
on celledit, i want the script not to allow to type special characters(!@#$%^&*()) except Alphanumeric(A-Z & 1-9).
Can you please help me.

Thnx
Murthy

7 REPLIES 7

adiddigi
Tera Guru

Here you go.

Client Script type: onCellEdit
Field Name : Field name you are validating it for.

Script:



function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below

saveAndClose = /^[a-zA-Z]+(\s+[a-zA-Z]+)?$/.test(newValue);
callback(saveAndClose);
}


Thummala_Murthy
Kilo Contributor

Hi Abhiram ,
Thanks for the script,
I tried this but seems like it is allowing me to enter special characters like !@#$%^&*().
and by the way i your code "saveAndClose = /^[a-zA-Z]+(\s+[a-zA-Z]+)?$/.test(newValue);" what is the test function?
what i need is when i type the keyboard, teh text box should allow only A-Z and 1-9 and not other special charcter.
can you pls help me. did you have this script working on any Demo. if so can u pls let me know that demo.

Thanks
Murthy


Works perfectly on https://demo010.service-now.com/ and is on incident table. It is on the field Description which I added to list view for you to test.

and the name of Client Script is : Description- Special Char

The test() is a function of Regular Expression - Link to MDN here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp


Thummala_Murthy
Kilo Contributor

Hi,
Pls check the Description field of Incident INC0010004 in https://demo010.service-now.com/
it allowed me to enter the special characters.

Thnx
Murthy