-1

im trying to get this regular expression to work but im having problems with javascript exception because of the case sensitive.

I have my regular expression in my model and some words should not be able to write such as "and" "or" "ok" "not. but if i write Andy it should work

[RegularExpression(@"^(?:(?!\b(?:AND|O[RK]|NOT|FALSE|TRUE)\b)[\wåäöÅÄÖ\._])*$\i", ErrorMessageResourceName

i can't use the regularoption ( Regex.ignoreCase) so im trying to use \i but getting javascript error.

what am i doing wrong?

tereško
  • 58,060
  • 25
  • 98
  • 150
Cosy
  • 1
  • 3

1 Answers1

4

You are using a backslash to use case insensitive flag but you need to use a forward slash like this:

var re = /^(?:(?!\b(?:AND|O[RK]|NOT|FALSE|TRUE)\b)[\wåäöÅÄÖ._])*$/i;
                                                         HERE----^
Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
  • @Cosy check this link http://regex101.com/r/sY7oH6/3. Take a look at Code Generator section to copy the javascript code – Federico Piazza Sep 03 '14 at 15:42
  • @Cosy btw, if you want you can edit your question and add some sample inputs and your desired output to point what are valid and invalid matches and I'd be able to provide another regex or help you with the existing one – Federico Piazza Sep 03 '14 at 15:44
  • i've tried that side but not getting the case sensitive :( ... Its driving me crazy :( . If i write AND it works but if i write And it doesn't work. I need to find where to put the i . I also trying on debuggex https://www.debuggex.com/#cheatsheet ... dead end too – Cosy Sep 03 '14 at 15:56
  • @Cosy your regex work fine http://debuggex.com/i/ZlGGjFR7bWJ3d6D-.png. If you put AND or and it won't match if you use andy it will. Your regex match words that aren't AND or OR or OK or NOT... etc – Federico Piazza Sep 03 '14 at 16:47
  • Its not kicking in when i write and in lower case so i need it to be case insensitive – Cosy Sep 04 '14 at 06:35
  • @Cosy you can check in this link http://regex101.com/r/sY7oH6/4 that everything is working. – Federico Piazza Sep 04 '14 at 15:08