views:

118

answers:

3

I Need a regular expression which accepts all types of characters (alphabets, numbers and all special characters), and miniumum number of characters should be 15 and no limit for maximum characters.

+4  A: 
.{15,}

Assuming that you use settings where the dot matches all characters. It's really hard to be any more specific unless you mention which platform you're using.

Matti Virkkunen
Hm, I guess the OP meant anything else then whitespace if I read it right, could be /^[^\s]{15,}/, which is pretty portable I think (there will always be exceptions though, so you're right to ask).
Wrikken
I am using asp.net.
KhanS
+3  A: 

The basic repetition options for regex are as follows:

  • x? matches zero or one x
  • x* matches zero or more x
  • x+ matches one or more x
  • x{3} matches exactly 3 x
  • x{3,} matches at least 3 x
  • x{3,5} matches at least 3 and at most 5 x

To match absolutely any character, you use . in single-line mode. To enable single-line mode, consult documentation for your specific language. In Java, this is (?s)/Pattern.DOTALL.

If by "all types of characters" you really mean everything but whitespace, then there's a special character class for that: \S (with a capital S). The pattern you're looking for is therefore:

  • \S{15,}

References

polygenelubricants
+1  A: 

Ehm.. Using a regular expression when you just want to check the length of a string? Try something like

inputString.Length >= 15

simendsjo