diff --git a/Client-Side Components/Catalog Client Script/Regex Validation/Adhaar Validation Script b/Client-Side Components/Catalog Client Script/Regex Validation/Adhaar Validation Script new file mode 100644 index 0000000000..9a16039144 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Regex Validation/Adhaar Validation Script @@ -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 + } + +} diff --git a/Client-Side Components/Catalog Client Script/Regex Validation/README.md b/Client-Side Components/Catalog Client Script/Regex Validation/README.md index f4bcb7aff4..7af8396178 100644 --- a/Client-Side Components/Catalog Client Script/Regex Validation/README.md +++ b/Client-Side Components/Catalog Client Script/Regex Validation/README.md @@ -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)