Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function onSubmit() {

g_form.hideFieldMsg('adhaar'); // hide previous field mesage.
/*
Adhaar validation script.
Adhaar is a 12 digit unique identification number issues by UIDAI in India for Indian Residents.
/^[2-9][0-9]{3}[0-9]{4}[0-9]{4}$/
// ^ → Start of the string
// [2-9] → The first digit must be between 2 and 9
// [0-9]{3} → Followed by exactly 3 digits (0–9)
// [0-9]{4} → Followed by exactly 4 digits (0–9)
// [0-9]{4} → Followed by exactly 4 digits (0–9)
// $ → End of the string
*/

var adhrNum = g_form.getValue('adhaar'); // adhaar variable name
var adharReg = /^[2-9][0-9]{3}[0-9]{4}[0-9]{4}$/; // adhaar regex
var regex = new RegExp(adharReg);

if (!regex.test(adhrNum)) {
g_form.clearValue('adhaar'); // clear field value
g_form.showFieldMsg('adhaar', "Please enter valid adhaar number", 'error', true);
return false; // stop form submission
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@

# Regular Expression on Catalog Client script

With the help of this code you can easily validate the input value from the user and if it's not a email format you can clear and throw a error message below the variable. Of course you can use Email type variable as well but you cannot have a formatted error message.

* [Click here for script](script.js)
*****************

8th october:

This script will validate the Adhaar number.

Adhaar is a 12 digit unique identification number issued by the Unique Identification Authority of India (UIDAI) for Indian residents.

The script will validate Adhaar through regex, and if it is not valid, the variable is cleared with a field message.

The preferred OOB method for catalog variables is listed here : https://www.servicenow.com/docs/bundle/xanadu-servicenow-platform/page/product/service-catalog-management/task/define-regex-vrble.html . The same regex can be defined in "Variable Validation Regex" module.


Regex details :

/^[2-9][0-9]{3}[0-9]{4}[0-9]{4}$/

// ^ → Start of the string

// [2-9] → The first digit must be between 2 and 9

// [0-9]{3} → Followed by exactly 3 digits (0–9)

// [0-9]{4} → Followed by exactly 4 digits (0–9)

// [0-9]{4} → Followed by exactly 4 digits (0–9)

// $ → End of the string

*****************

With the help of this code, you can easily validate the input value from the user. If it is not an Adhaar, you can clear it and throw an error message below the variable. The same validation can be used for fields instead of variables.

* [Click here for script](script.js)


Loading