Disallow Special Characters to enter in text field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2013 09:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2013 08:52 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2013 09:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2013 09:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2013 09:58 AM
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