Javascript / .NET regex

I need a Javascript and .NET regular expression that validates a string and lets you know if a string contains only one character except a space.

I want users not introduced something like "wwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

I feel so bad at regex, so I'm sorry I didn't come with the code.

+3
source share
1 answer
 string [] inputs = {" sdfasf asdf ", " wwwwww wwwwwww ", " aaaaa bbbb ccccccc"};
 foreach (string input in inputs)
 {
    var match = Regex.Match (input, @"^\s*(\w)(?:\1|\s)*$");
    Console.WriteLine (input + "\t" + match.Success);
 }

, , javascript. # :

sdfasf asdf    False
wwwwww wwwwwww         True
aaaaa bbbb ccccccc     False
+2

All Articles