Variable must contain 12 numeric characters and not allowed single space in variable regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @mani55
Try with this:
^\d{12}$
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
see the AWS account ID variable i just given 12 spaces but still accepting but i don't need accept
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @mani55 ,
Please try using below steps
Steps:
- Go to Question Regular Expressions (question_regex.list)
- Create a new record with your regex ^\d{12}$ and a user-friendly error message
- Open your Variable record on the Catalog Item
- Under Type Specifications → set Validation Regex to the record you just created
Clean, no-code approach and fully supported OOB. No client script needed.
Regards
Aanchal Agarwal