Variable must contain 12 numeric characters and not allowed single space in variable regex

mani55
Tera Contributor

Variable must contain 12 numeric characters and not allowed single space in variable regex

 

For example there are given only 4 spaces or 12 spaces on that time also not allowed 

 

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @mani55 

 

Try with this:

^\d{12}$

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

CN-L
Kilo Sage

Hi @mani55,

 

I'm not sure that the regex can physically stop a user from being able to type a space, however the OOTB number regex will produce an error message if any non-number characters are entered.

 

CNL_2-1782387413513.png

 

As an alternative approach, you could create an onChange client catalog script that will notify the user if they have not entered a specific minimum number of characters. For example:

CNL_3-1782387460740.png

 

Below is the script I used:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    var minLength = 12; // Set your minimum character requirement here

    if (newValue.length < minLength) {
        g_form.showFieldMsg('your_variable_name', "Input must be at least " + minLength + " characters long.", 'error');
    } else {
        g_form.hideFieldMsg('your_variable_name'); // Clears the error once they type enough characters
    }
}

 

If you haven't already, you can also set the maximum number of characters that can be entered by adding max_length=12 to the variable attribute to stop users from being able to enter too many characters.


Powered by caffeine, curiosity, and more failed attempts than I'd like to admit