- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2024 11:56 PM - edited 10-28-2024 12:54 AM
Hello everyone,
How can we restrict a field to only accept combination of letter and number values or all letters only?
- Should not accept if field purely contains numeric values
- Should not accept if field contains any special characters
Basically at least 1 letter and 1 number or All letters only.
Sample: ABCGSM, GSMXWX1, AZXSSS, SVCSAL8
Using onChange client script.
Thanks !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 12:55 AM
Hi @ss123 ,
Please use below regEx for your field -
var regex = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d\s]*$|^[a-zA-Z\s]+$/;
You can create an OnChange Client script for your field -
For example, I have implemented it for the incident Short Description field. If the value fails validation, it will be cleared from the field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return; // Skip validation if the field is empty or the form is loading
}
// Define the regex pattern
var regex = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d\s]*$|^[a-zA-Z\s]+$/;
// Test the new value against the regex
if (!regex.test(newValue)) {
g_form.clearValue('short_description'); // Optionally clear the field
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.
Thank you!
Moin Kazi
www.linkedin.com/in/moinuddinkazi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 01:11 AM
Thank you @Moin Kazi !
this is working 🙂