Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8336697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:04:35+00:00 2026-06-09T04:04:35+00:00

I am trying to check a valid Regex expression, with this class: using System.Text.RegularExpressions;

  • 0

I am trying to check a valid Regex expression, with this class:

using System.Text.RegularExpressions;

namespace Checking
{
    public static class CheckALF
    {
        public static bool IsValueOk(string value)
        {
            Regex isValidNumber = new Regex(@"^\d{1,3}(?:I|D|R)?", RegexOptions.IgnoreCase);
            if (isValidNumber.IsMatch(value)) {
                return true;
            }
            return false;            
        }

    }
}

To facilitate regexp expression construct I use:
http://www.radsoftware.com.au/regexdesigner/

But I have tried a lot of things that are running on ‘regexdesigner’ but not in C# .net 4 so I am a bit loss with this.

I put here the test code (only partially) with the failing test.

using Checking;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestCheck
{
    [TestClass]
    public class TestCheckALF
    {
        [TestMethod]
        public void Check_IsValid_OnlyNumbers_LessThan3Digits()
        {
            Assert.IsTrue(CheckALF.IsValueOk("40"));
            Assert.IsTrue(CheckALF.IsValueOk("0"));
            Assert.IsTrue(CheckALF.IsValueOk("999"));
        }

        [TestMethod]
        public void Check_IsValid_OnlyNumbersMoreThan3Digits()
        {
            Assert.IsFalse(CheckALF.IsValueOk("1000"));  //  ERROR.......
        }

        [TestMethod]
        public void Check_IsValid_NumbersAndR_LessThan3Digits()
        {
            Assert.IsTrue(CheckALF.IsValueOk("40R"));
            Assert.IsTrue(CheckALF.IsValueOk("0R"));
            Assert.IsTrue(CheckALF.IsValueOk("999R"));
        }

        [TestMethod]
        public void Check_IsValid_NumbersAndL_LessThan3Digits()
        {
            Assert.IsTrue(CheckALF.IsValueOk("40I"));
            Assert.IsTrue(CheckALF.IsValueOk("0i"));
            Assert.IsTrue(CheckALF.IsValueOk("999I"));
        }
    }
}

Thanks in advance.


Edit 2 (IMPORTANT)

RegExDesigner was failing expressions because the expression has a new line at the end. I mean:

^\d{1,3}(?:I|D|R)?
<new line>

But it fails as you can see in the second ‘screenshot’ below. And it has the right expression used in C# code, this one:
^\d{1,3}(?:I|D|R)?$

Edit 1

I copy here two screenshots from RegExDesigner:

First screenshot from RegExDesigner

Second screenshot from RegExDesigner -with Daniel advice-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:04:36+00:00Added an answer on June 9, 2026 at 4:04 am

    You need to anchor the regex not only at the beginning but also at the end:

    @"^\d{1,3}(?:I|D|R)?$"
    

    Note the $ at the end of the expression.

    1000 matches, because the first three digits match the expression. And without the missing anchor at the end, it is valid, that there are unmatching characters after that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to check whether numbers are valid using the code below. Will this
I'm trying to find a regex that will check for a valid mask. The
I'm trying to check a string with a regular expression, and this check should
I am trying to run through a program to check if vouchers are valid
I'm trying to check if a file exists. If I use this: NSData *data
I am trying to check that my NSOpenGLView has a valid context but it
I am trying to build a PHP class to check the username and password
I'm trying to write a regular expression that will check so a given string
I'm trying to check if a user submitted URL is valid, it goes directly
Possible Duplicate: Regex for checking if a string has mismatched parentheses? I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.