0

I mean like this

" T" It's no 3 Character
"T T" It's no 3 Character
" T " It isn.
"TTT" It's true
" TTT" is true
" TT T" is true

how to check that with regex

i'm trying "^[\s]{3,100}$" but it does'nt work

Thanks.

1
  • What do you want the answer to be for each one of the examples you gave? Commented Feb 6, 2012 at 8:47

3 Answers 3

1

I'm assuming you want to test for at least three non-whitespace characters. In which case this pattern should work. ^\s*(\S\s*){3,100}$

    [Test]
    public void Test()
    {
        Regex pattern = new Regex(@"^\s*(\S\s*){3,100}$");

        Assert.IsFalse(pattern.IsMatch(" T"));
        Assert.IsFalse(pattern.IsMatch("T T"));
        Assert.IsFalse(pattern.IsMatch(" TT"));
        Assert.IsTrue(pattern.IsMatch("TTT"));
        Assert.IsTrue(pattern.IsMatch(" TTT"));
    }

What isn't clear from your question is if white space is allowed or if the match should fail if any white space is present.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. but I'am try this " TTT" i'm type with 2 or more space in first it's not work, validator read not 3 characters entered. Thanks before
I've updated the pattern to allow a proceeding \s* to work with your " TTT" scenario.
0

I would say in Java because I am not familiar with asp.net (I am pretty sure you have lenght on String and replaceAll (regex, replacement) in asp.net as well):

System.out.println(input.length() == input.replaceAll("\\s", "").length());

Comments

0

You can use regex /(\w)\1{2,}/ to match any character, followed by two or more of the same character like this in JavaScript: (you will have to translate to ASP.NET)

a = [" T ", "  T", "T  ", "TTT", "TTAT"]

for(i=0;i<a.length;i++)
  console.log(i, a[i], a[i].match(/(\w)\1{2,}/) != null)

1 Comment

Does this address "minimum characters without count whitespace" ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.