- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2021 12:31 PM
I have a requirement to validate a field which should not have the following characters ' @ , . / \ ' .
I am using the following script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var specialCharRegex = /[^/@,.\\]/;
if(specialCharRegex.test(newValue))
{
alert('Please re-enter a valid database name. Special characters such as [@ . /] are not allowed.');
}
g_form.setValue('database_name', '');
}
.......
This script is not validating as per the requirement. Please advice.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 11:18 AM
After few trials and errors, used the following code which worked finally 🙂
if( newValue.indexOf('@')> -1 || newValue.indexOf(',')> -1 || newValue.indexOf('/')> -1 || newValue.indexOf('\\')> -1 || newValue.indexOf('.')>-1){
alert('Please re-enter a valid database name. Special characters such as \\ , @ . / are not allowed.');
g_form.setValue('database_name', '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2021 12:37 PM
Hi Amrita,
Please try below link.
https://community.servicenow.com/community?id=community_question&sys_id=1906a3f4dbfdb3485129a851ca961997
Thanks,
Siddiq
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 11:18 AM
After few trials and errors, used the following code which worked finally 🙂
if( newValue.indexOf('@')> -1 || newValue.indexOf(',')> -1 || newValue.indexOf('/')> -1 || newValue.indexOf('\\')> -1 || newValue.indexOf('.')>-1){
alert('Please re-enter a valid database name. Special characters such as \\ , @ . / are not allowed.');
g_form.setValue('database_name', '');
}