- 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 12:09 AM
Hi,
You can use Regular Expression Field Validation for this requirement. Refer the below URL to create Regular Expression Field Validation:
For alphanumeric, use the below regular expression
^[a-zA-Z0-9]*$
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 12:24 AM
Hi @palanikumar
Thanks but it should not accept pure numbers.
Accepted value should be pure letters or combination of letter/number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 01:11 AM
Hi@ss123 ,
You can try the below onChange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var numericPattern = /^(?!\d+$)(?=.*[A-Za-z])[A-Za-z0-9]+$/; // Regular expression pattern for numeric input
if (!numericPattern.test(newValue)) {
alert('Please enter only letters or a combination of letters and numbers. No pure numbers or special characters allowed.');
g_form.setValue('your_field_value', '');
}
}
The above link will help you test your accepted inputs. Add the following expression:
/^(?!\d+$)(?=.*[A-Za-z])[A-Za-z0-9]+$/ and test it.
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish
- 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~