.NET regex's not working - 1# check beginning of text entered #2 check structure
Posted
by
Olly
on Stack Overflow
See other posts from Stack Overflow
or by Olly
Published on 2012-12-06T17:02:03Z
Indexed on
2012/12/06
17:03 UTC
Read the original article
Hit count: 400
OK it has unfortunately been a while since I've used REGEX and I am struggling to wonder why its not working with my project.
I have used Regex Tester which says my two tests are valid but when it comes to testing in my project they get rejected.
1) Check the text starts with certain characters
[RegularExpression("(spAPP)",ErrorMessage = "Stored procedures must begin with spAPP")]
This seems to accept spAPP on it's own, but not something like spAPPabcdef which I want it to. I am struggling to find the "Ignore rest of the text" attribute with REGEX.
2) A bit more complicated. I have certain naming conventions for AD groups, so an example would be "UK ROLE IT APPLICATION DEV ADMIN", up to the role name there are standards (so I need the "UK ROLE IT APPLICATION DEV" checked.
[RegularExpression(@"((UK|FRANCE|GERMANY|USA)\s(ROLE)\s(IT|NON-IT)\s(APPLICATION)\s(DEV|TEST|LIVE))", ErrorMessage = "Please use AD naming standards.")]
I think it might be the fact I am using () around all the words, but its easier to read in my code. The RegexTester I found seems to indicate that it's right, but again, in my .NET project, it rejects it.
Thanks,
© Stack Overflow or respective owner