Skip to content

Commit fed228f

Browse files
authored
Adhaar validation script (#1952)
1 parent 13ee70d commit fed228f

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function onSubmit() {
2+
3+
g_form.hideFieldMsg('adhaar'); // hide previous field mesage.
4+
/*
5+
Adhaar validation script.
6+
Adhaar is a 12 digit unique identification number issues by UIDAI in India for Indian Residents.
7+
/^[2-9][0-9]{3}[0-9]{4}[0-9]{4}$/
8+
// ^ → Start of the string
9+
// [2-9] → The first digit must be between 2 and 9
10+
// [0-9]{3} → Followed by exactly 3 digits (0–9)
11+
// [0-9]{4} → Followed by exactly 4 digits (0–9)
12+
// [0-9]{4} → Followed by exactly 4 digits (0–9)
13+
// $ → End of the string
14+
*/
15+
16+
var adhrNum = g_form.getValue('adhaar'); // adhaar variable name
17+
var adharReg = /^[2-9][0-9]{3}[0-9]{4}[0-9]{4}$/; // adhaar regex
18+
var regex = new RegExp(adharReg);
19+
20+
if (!regex.test(adhrNum)) {
21+
g_form.clearValue('adhaar'); // clear field value
22+
g_form.showFieldMsg('adhaar', "Please enter valid adhaar number", 'error', true);
23+
return false; // stop form submission
24+
}
25+
26+
}
Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
1+
12
# Regular Expression on Catalog Client script
2-
3-
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.
43

5-
* [Click here for script](script.js)
4+
*****************
5+
6+
8th october:
7+
8+
This script will validate the Adhaar number.
9+
10+
Adhaar is a 12 digit unique identification number issued by the Unique Identification Authority of India (UIDAI) for Indian residents.
11+
12+
The script will validate Adhaar through regex, and if it is not valid, the variable is cleared with a field message.
13+
14+
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.
15+
16+
17+
Regex details :
618

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

21+
// ^ → Start of the string
22+
23+
// [2-9] → The first digit must be between 2 and 9
24+
25+
// [0-9]{3} → Followed by exactly 3 digits (0–9)
26+
27+
// [0-9]{4} → Followed by exactly 4 digits (0–9)
28+
29+
// [0-9]{4} → Followed by exactly 4 digits (0–9)
30+
31+
// $ → End of the string
32+
33+
*****************
34+
35+
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.
36+
37+
* [Click here for script](script.js)
838

939

0 commit comments

Comments
 (0)