diff --git a/Specialized Areas/Regular Expressions/Check if number has 10 digits/README.md b/Specialized Areas/Regular Expressions/Check if number has 10 digits/README.md index 404f82bbdb..5ff97aacd6 100644 --- a/Specialized Areas/Regular Expressions/Check if number has 10 digits/README.md +++ b/Specialized Areas/Regular Expressions/Check if number has 10 digits/README.md @@ -1 +1,11 @@ -Script is used to check if the number has 10 digts( you can update the digit count in the code based on the need. +# Digit Length Validator + +## Description + +This script checks if a string contains exactly a specified number of digits. Useful for validating numeric input. The digit count can be adjusted in the code. + +## Usage +To change the required digit count, update the number in the regular expression +``` +var digitLengthRegex = /^\d{N}$/; // Replace N with desired digit count +``` diff --git a/Specialized Areas/Regular Expressions/Check if number has 10 digits/script.js b/Specialized Areas/Regular Expressions/Check if number has 10 digits/script.js index ec7d84ab53..e99b0b1962 100644 --- a/Specialized Areas/Regular Expressions/Check if number has 10 digits/script.js +++ b/Specialized Areas/Regular Expressions/Check if number has 10 digits/script.js @@ -1,7 +1,9 @@ -var reg = '/^\d{10}$/'; // Update the number based on the need +var digitLengthRegex = /^\d{10}$/; // Matches exactly 10 digits -var k = '123456789144'; // example +var elevenString = '01234567899'; // 11 digits +var tenString = '0123456789'; // 10 digits +var nineString = '012345678'; // 9 digits - if (/^\d{10}$/.test(k)){ // This will check if it has 10 digits - -} +gs.info(digitLengthRegex.test(elevenString)); // false +gs.info(digitLengthRegex.test(tenString)); // true +gs.info(digitLengthRegex.test(nineString)); // false