- 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:47 PM
It's your choice where you want to display the error message. As it's an onchange client script for description field, it'll work only for the description field and if you make any change to the business application field, the logic will not execute.
In your case you will only be able to validate both fields iff you make changes to the description field at the end. Otherwise you can have another onchange client script or onsubmit one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 11:52 PM
Hello @J_31 ,
Can you please elaborate the requirement and let me know exactly what you want to validate and you can show the display error message for the field using show field message and in your case you will need either 2 on change client scripts or one onSubmit client script. But it's better to have only one with onSubmit.
Also paste the code here if possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 12:10 AM
How to
acheive using single
onsubmit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 12:31 AM
Hello @J_31 ,
Yes , so please give a try to the script which I gave you earlier and let me know your views on this.