- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 04:59 AM
Hi All,
Please let me know how to apply these all conditions. I have one single line text field ( Name of the project).
I should want to restrict that field as per the below requirement:
Name of the project can't contain special characters, such as / : \ ~ & % ; @ ' " ? < > | # $ * } { , + = [ ], can't begin with an underscore, can't begin or end with a period, and must be 64 or fewer characters.
Please provide the code.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:15 AM
@Sirri You can do onSubmit or onChange script below is sample script.
function onSubmit() {
var projectName = g_form.getValue('name_of_project'); // Replace 'name_of_project' with your field name.
// Disallowed special characters.
var specialCharPattern = /[\/:\\~&%';"<>|#\$\*\}\{\[\],+=]/;
// Check for special characters.
if (specialCharPattern.test(projectName)) {
g_form.showErrorBox('name_of_project', 'Project name cannot contain special characters like / : \\ ~ & % ; @ \' " ? < > | # $ * } { , + = [ ]');
return false;
}
// Check if the string starts or ends with a period or underscore.
var regex = /^[a-zA-Z0-9][a-zA-Z0-9\s\-._]{0,62}[a-zA-Z0-9]$/;
if (!regex.test(projectName)) {
g_form.showErrorBox('name_of_project', 'Invalid project name. Project name must be alphanumeric, cannot start with underscore or period, and cannot contain special characters.');
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:32 AM
Hi @Sirri Try below onChange Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var projectNamePattern = /^[^_\s][^\/:\~\&\%\;\@\^\{\}\[\]\<\>\|\#\$\*\?\'\"\+\=\,\.]{1,63}[^\.]$/;
if (!projectNamePattern.test(newValue)) {
g_form.showFieldMsg('u_name_of_the_project', 'Name of the project cannot contain special characters, cannot begin with an underscore, cannot begin or end with a period, and must be 64 or fewer characters.', 'error');
g_form.setValue('u_name_of_the_project', oldValue);
} else {
g_form.hideFieldMsg('u_name_of_the_project');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:15 AM
@Sirri You can do onSubmit or onChange script below is sample script.
function onSubmit() {
var projectName = g_form.getValue('name_of_project'); // Replace 'name_of_project' with your field name.
// Disallowed special characters.
var specialCharPattern = /[\/:\\~&%';"<>|#\$\*\}\{\[\],+=]/;
// Check for special characters.
if (specialCharPattern.test(projectName)) {
g_form.showErrorBox('name_of_project', 'Project name cannot contain special characters like / : \\ ~ & % ; @ \' " ? < > | # $ * } { , + = [ ]');
return false;
}
// Check if the string starts or ends with a period or underscore.
var regex = /^[a-zA-Z0-9][a-zA-Z0-9\s\-._]{0,62}[a-zA-Z0-9]$/;
if (!regex.test(projectName)) {
g_form.showErrorBox('name_of_project', 'Invalid project name. Project name must be alphanumeric, cannot start with underscore or period, and cannot contain special characters.');
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:32 AM
Hi @Sirri Try below onChange Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var projectNamePattern = /^[^_\s][^\/:\~\&\%\;\@\^\{\}\[\]\<\>\|\#\$\*\?\'\"\+\=\,\.]{1,63}[^\.]$/;
if (!projectNamePattern.test(newValue)) {
g_form.showFieldMsg('u_name_of_the_project', 'Name of the project cannot contain special characters, cannot begin with an underscore, cannot begin or end with a period, and must be 64 or fewer characters.', 'error');
g_form.setValue('u_name_of_the_project', oldValue);
} else {
g_form.hideFieldMsg('u_name_of_the_project');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 03:06 AM
Hi Sid,
Please let me know why used test in the if condition as per the below.
if (!projectNamePattern.test(newValue))
Thank you