- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 11:42 PM - edited 12-25-2023 11:43 PM
Hi I want to validate the text entered inside the first two question using client script
below is the script - should I want display error message below the field ;
script is working for description but not for the first one,
also should I try the same using on submit?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 12:16 AM
Hello @J_31 ,
Please let me know your views on my earlier queries and till then you can try with the below onSubmit client script.
onSubmit Client Script :
function onSubmit() {
var descfield = g_form.getValue('description');
var ba = g_form.getValue('business_application');
const regex = /^[A-Z0-9a-z]+$/;
var descValid = regex.test(descfield);
var baValid = regex.test(ba);
if (!descValid) {
g_form.clearValue('description');
g_form.showFieldMsg('description', 'Description must contain only alphanumeric characters', 'error');
}
if (!baValid) {
g_form.clearValue('business_application');
g_form.showFieldMsg('business_application', 'Business Application must contain only alphanumeric characters', 'error');
}
// Allow form submission only if both fields are valid
if (!descValid || !baValid) {
return false; // Prevent form submission
}
return true; // Allow form submission
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 11:52 PM
Hi @J_31 ,
If you want the script to run on change of both the fields i.e business application n description then u do need to create on change script for both. Current script u can just copy paste n use it for business application field as well.
Also if the form will be used on portal please keep UI type as ALL. Currently it's set to desktop on portal that validation will not work.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 12:16 AM
Hello @J_31 ,
Please let me know your views on my earlier queries and till then you can try with the below onSubmit client script.
onSubmit Client Script :
function onSubmit() {
var descfield = g_form.getValue('description');
var ba = g_form.getValue('business_application');
const regex = /^[A-Z0-9a-z]+$/;
var descValid = regex.test(descfield);
var baValid = regex.test(ba);
if (!descValid) {
g_form.clearValue('description');
g_form.showFieldMsg('description', 'Description must contain only alphanumeric characters', 'error');
}
if (!baValid) {
g_form.clearValue('business_application');
g_form.showFieldMsg('business_application', 'Business Application must contain only alphanumeric characters', 'error');
}
// Allow form submission only if both fields are valid
if (!descValid || !baValid) {
return false; // Prevent form submission
}
return true; // Allow form submission
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket