3

I am currently using Regex and I have absolutely no idea how to. I got somewhere with the help of msdn, but not far enough:

So below I copied and pasted Regex code that I want to include with another rule I need. This code below does not allow special characters as well as numbers in the field:

[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$", ErrorMessage = 
        "Numbers and special characters are not allowed in the Title.")]

I need this as well as a restriction on using capital letters after every space.

Example: Every Day I Learn Something New <--Correct
but not: Every day i learn something new. <--Incorrect

Just like making a title for an article.

If you can help out an uneducated Regex coder that would be much appreciated

Cheers

1011 1110
  • 743
  • 2
  • 17
  • 43
  • 3
    FYI, some of us have lowercase words as part of our names.. Example: http://en.wikipedia.org/wiki/Alexander_von_Humboldt - also, movie/book titles will often have lowercased 'of', 'a', etc. – Blorgbeard Jan 30 '14 at 00:09
  • mmm, thanks for the insight. I wonder if that would be an issue for my client. I guess maybe leaving that tad-bit out would be more beneficial then not. – 1011 1110 Jan 30 '14 at 00:17

2 Answers2

1
([A-Z]+[A-Za-z]*\s+)*

You can test your Regex on this site Regex Tester

Amir Katz
  • 1,027
  • 1
  • 10
  • 24
1

This question describes how to do negative matches. For your case, you could also require that string match @"^((?!\s[a-z]).)*$".

Community
  • 1
  • 1
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152