Field should only have at least 1 letter and 1 number only

ss123
Tera Contributor

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 !

1 ACCEPTED SOLUTION

Moin Kazi
Kilo Sage
Kilo Sage

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

View solution in original post

5 REPLIES 5

ss123
Tera Contributor

Thank you @Moin Kazi ! 

this is working 🙂