-
Notifications
You must be signed in to change notification settings - Fork 917
Adhaar validation script #1945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adhaar validation script #1945
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| var regex = new RegExp(adharReg); | ||
|
|
||
| if (!regex.test(adhrNum)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
There was a problem hiding this comment.
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