Skip to content
Closed
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,18 @@
function onSubmit() {

g_form.hideFieldMsg('adhaar'); // hide previous field mesage.
/*
Adhaar validation script.
*/

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break down the regex in the comment and readme so users know what is checked.
I would include what Adhaar is, as it is specific to India "Aadhaar is a 12-digit unique identification number issued by the Unique Identification Authority of India (UIDAI) to residents of India".
Then break down the regex:

/^[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 regex = new RegExp(adharReg);

if (!regex.test(adhrNum)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is OOTB functionality that allows for this regex to be evaluated. Please have a look at this: https://www.servicenow.com/community/developer-articles/field-validation-regular-expressions/ta-p/2321095

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,5 +1,12 @@
# Regular Expression on Catalog Client script


*****************
8th october:
This script will validate valid Adhaar number.
Adhaar is a 12 digit unique identification number issues by UIDAI in India.
The script will validate Adhaar through regex and if it is not valid, variable is cleared with field message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what the regex does/how it is build up.


*****************
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated, include a comment that there is OOTB functionality that is prefered over this.


* [Click here for script](script.js)
Expand Down
Loading