We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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 

 

4 REPLIES 4

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

see the AWS account ID variable i just given 12 spaces but still accepting but i don't need accept

mani55_0-1782793586928.png

 

CN-L
Mega 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

Aanchal Agarwa1
Tera Expert

Hi @mani55 ,

Please try using below steps

 

Steps:

  1. Go to Question Regular Expressions (question_regex.list)
  2. Create a new record with your regex ^\d{12}$ and a user-friendly error message
  3. Open your Variable record on the Catalog Item
  4. Under Type Specifications → set Validation Regex to the record you just created

Clean, no-code approach and fully supported OOB. No client script needed.

 

AanchalAgarwa1_0-1782410865105.png

 

AanchalAgarwa1_1-1782410881776.png

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Aanchal Agarwal