Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex, Making A Basic Title

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

like image 248
1011 1110 Avatar asked Apr 24 '26 00:04

1011 1110


2 Answers

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

like image 171
ChaseMedallion Avatar answered Apr 26 '26 14:04

ChaseMedallion


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

You can test your Regex on this site Regex Tester

like image 44
Amir Katz Avatar answered Apr 26 '26 14:04

Amir Katz