From 56335066ab9dfb250d6904cdf687a7ebf00d1485 Mon Sep 17 00:00:00 2001 From: Willem Date: Sun, 12 Oct 2025 14:03:19 +0200 Subject: [PATCH 1/2] Update script.js - Renamed variable reg to digitLengthRegex to better reflect its purpose. - Replaced string-based regex ('/^\d{10}$/') with a proper RegExp object. - Added test cases for strings with 9, 10, and 11 digits to demonstrate expected behavior. - Improved inline comments. --- .../Check if number has 10 digits/script.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 From a06b4e4c2185975782b65021c9b01999e7d40f9e Mon Sep 17 00:00:00 2001 From: Willem Date: Sun, 12 Oct 2025 14:06:37 +0200 Subject: [PATCH 2/2] Update README.md Updated the readme to be more descriptive. --- .../Check if number has 10 digits/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 +```