Event Receivers / Regular Expressions
Hi, I have an Event Receiver which aims to ensure that the first letter of a word is a capital. I would like to use regular expressions, but I am new to it. Here's the code. Basically, what I would like to happen is that the Event Receiver comes up if the word does not have a capital letter at its start in when entered in the DayNew column. What regular expression code should I use? I have tried the below, but is doesn't work. if (!string.IsNullOrEmpty(sDayNew)) { if (!System.Text.RegularExpressions.Regex.IsMatch(sDayNew, @"^[a-z]$")) { properties.Cancel = true; } } THANKS! Zuke zuke collins
September 25th, 2012 9:57am

Hi Why don't you try using char.IsUpper(sDayNew,0) instead of using a Regular Expression. Regards, PedroPedro Aparcana
Free Windows Admin Tool Kit Click here and download it now
September 25th, 2012 4:18pm

Hi Why don't you try using char.IsUpper(sDayNew,0) instead of using a Regular Expression. Regards, PedroPedro Aparcana
September 25th, 2012 4:36pm

Hi Pedro, That's great - I was using Regular Expressions as I was working off an exercise from a book. However, what would you do if, for example you wanted to check that the start of each word was upper case and you had three words? Many thanks Zukezuke collins
Free Windows Admin Tool Kit Click here and download it now
September 26th, 2012 6:52am

I don't know much about regular expressions but I would do this : string splitWords = sDayNew.Split(' '); bool isOk = true; for(int i = 0; i < splitWords.Length; i++) if(!char.IsUpper(splitWords[i][0]) isOk = false; if(!isOk) { // here you put the code if every word doesn't start with a capital letter. } This is just one solution, maybe you can do it by using regex in some other wayPedro Aparcana
September 26th, 2012 11:02am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics