
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:55 AM
I have a variable that is a single line text field. The customer wants to ensure that these conditions are met. Is there a way to accomplish this?
Must NOT contain the following printable characters: / : \ ~ & % ; @ ' " ? < > | # $ * } { , + = [ ].
Must NOT start with an underscore (_).
Thanks,
Karen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 08:34 AM
Here's one that does both AND wipes the field:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var nospec = g_form.getValue('nospecial');
var ucheck = nospec.startsWith("_");
var pattern = new RegExp(/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/); //unacceptable chars
if (pattern.test(nospec)){
alert("No special characters!");
g_form.setValue('nospecial', '');
return false;
}
if (ucheck){
alert("Cannot start with an underscore");
g_form.setValue('nospecial', '');
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:57 AM
Hey Kbrownibx,
did you tried with Regular expression?
Let me know if you need more help
Thanks,
Rajashekhar Mushke
Community Leader - 18
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 08:00 AM
This looks like a good example:
https://stackoverflow.com/questions/11896599/javascript-code-to-check-special-characters

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 08:09 AM
Hey Shane,
I am trying this and I keep getting a Java console error and I am not sure why. Here is how I have the script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var iChars = "~`!#$%^&*+=-[]\\\';,/{}|\":<>?";
if(!iChars.test(/\W/g)){
alert ("File name has special characters ~`!#$%^&*+=-[]\\\';,/{}|\":<>? \nThese are not allowed\n");
return false;
}
}
Thanks Karen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 08:27 AM
I started from scratch based on the link I gave. This seems to work for me ( nospecial being the name of the String variable I used):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var nospec = g_form.getValue('nospecial');
var pattern = new RegExp(/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/); //unacceptable chars
if (pattern.test(nospec)){
alert("No special characters!");
return false;
}
return true;
}
Note this doesn't help with the underscore piece.