Skip to content

Adhaar validation script#1945

Closed
raghavs046 wants to merge 3 commits intoServiceNowDevProgram:mainfrom
raghavs046:adhaarValidationScript
Closed

Adhaar validation script#1945
raghavs046 wants to merge 3 commits intoServiceNowDevProgram:mainfrom
raghavs046:adhaarValidationScript

Conversation

@raghavs046
Copy link
Contributor

@raghavs046 raghavs046 commented Oct 8, 2025

PR Description:

replace this with your description

Pull Request Checklist

Overview

  • [] Put an x inside of the square brackets to check each item.
  • [] I have read and understood the CONTRIBUTING.md guidelines
  • [] My pull request has a descriptive title that accurately reflects the changes and the description has been filled in above.
  • [] I've included only files relevant to the changes described in the PR title and description
  • [] I've created a new branch in my forked repository for this contribution

Code Quality

  • My code is relevant to ServiceNow developers
  • My code snippets expand meaningfully on official ServiceNow documentation (if applicable)
  • I've disclosed use of ES2021 features (if applicable)
  • I've tested my code snippets in a ServiceNow environment (where possible)

Repository Structure Compliance

  • I've placed my code snippet(s) in one of the required top-level categories:
    • Core ServiceNow APIs/
    • Server-Side Components/
    • Client-Side Components/
    • Modern Development/
    • Integration/
    • Specialized Areas/
  • I've used appropriate sub-categories within the top-level categories
  • Each code snippet has its own folder with a descriptive name

Documentation

  • I've included a README.md file for each code snippet
  • The README.md includes:
    • Description of the code snippet functionality
    • Usage instructions or examples
    • Any prerequisites or dependencies
    • (Optional) Screenshots or diagrams if helpful

Restrictions

  • My PR does not include XML exports of ServiceNow records
  • My PR does not contain sensitive information (passwords, API keys, tokens)
  • My PR does not include changes that fall outside the described scope

*/

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 adharReg = /^[2-9][0-9]{3}[0-9]{4}[0-9]{4}$/; // adhaar regex
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

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.

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

*****************
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants