what does
numericregex = @"^[0-9]{5}
means?
because i want to set minimum 4 maximum 18
what does
numericregex = @"^[0-9]{5}
means?
because i want to set minimum 4 maximum 18
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted May 25, 2023, 3:08 PM EDT
In C#, you can use the following regular expression (regex) pattern to enforce a minimum length of 4 and a maximum length of 18:
string pattern = @"^.{4,18}$";Amit MohantyRank #112 · 20K reputationPosted May 25, 2023, 10:05 AM EDT
The expression
@"^[0-9]{5}"is a regular expression pattern that matches a string consisting of exactly five numeric digits (0-9) at the beginning of the string. To enforce the minimum number of 4 and maximum number of 18 in C#, you can utilize the following pattern:string numericRegex = @"^(?:[4-9]|1[0-8])$";Janarthanan SRank #224 · 11K reputationPosted May 25, 2023, 10:26 AM EDT
To modify the regular expression to match a minimum of 4 and a maximum of 18 digits, you can update it as follows:
numericregex = @"^[0-9]{4,18}"The modification involves using a quantifier
{4,18}after the character class[0-9]. This quantifier specifies that the preceding character class (digit) should occur at least 4 times and at most 18 times.Jignesh KumarRank #91 · 22.9K reputationPosted May 26, 2023, 12:39 AM EDT
Hi Nasir,
Please check below one,
using System; using System.Text.RegularExpressions; string input = "123"; // Example less then 4 string regexPattern = @"^\d{4,18}$"; bool isMatch = Regex.IsMatch(input, regexPattern); Console.WriteLine(isMatch); // Output is falseusing System; using System.Text.RegularExpressions; string input = "123234234"; // Example between 4 to 18 string regexPattern = @"^\d{4,18}$"; bool isMatch = Regex.IsMatch(input, regexPattern); Console.WriteLine(isMatch); // Output is trueMohit KalaRank #948 · 2.2K reputationPosted May 26, 2023, 1:54 AM EDT
string regexPattern= @"^\d{4,18}$";
it will allow min 4 digit and max 18 digits
Subarta RayRank #336 · 7.4K reputationPosted Dec 26, 2023, 7:59 AM EST
The provided regular expression
^[0-9]{5}is designed to match a string that:^asserts the start of the string.[0-9]matches any digit from 0 to 9.{5}specifies that there should be exactly five digits.So,
^[0-9]{5}matches a string that starts with exactly five digits.If you want to modify this regex to set a minimum of 4 and a maximum of 18 digits, you can use the following pattern:
string numericRegex = @"^[0-9]{4,18}";
Anandu G NathRank #681 · 3.5K reputationPosted Dec 26, 2023, 10:46 PM EST
@Basit Nisar
You can use the below code
numericregex = @"^[0-9]{4,18}"