This project is read-only.

Unicode character groups

Mar 5, 2010 at 2:22 PM
Edited Mar 5, 2010 at 7:06 PM

I'm working with xVal with a Regex DataAnnotation that looks like this: "^[\w\s\p{P}]*$"

It works fine on the server side, and .NET recognizes the \p{P} to mean the Unicode character group "Punctuation". xVal doesn't seem to pick that up though... Interestingly, it WILL pick up this: "^[\w\s\p{Punctuation}]*$"

But then .NET won't recognize it. I'm assuming that this is because xVal is leveraging the native Javascript RegEx implementation for pattern matching, and thus is at the whims of whether or not certain RegEx standards are implemented in a given browser... In my case, I'm using FireFox 3.6. Interestingly, Google Chrome doesn't have this issue, as I suspect that it's javascript implementation supports the unicode character groups.

Has any thought been put into converting character groups to their unicode equivalents in the xVal library prior to putting them into the Javascript code?

Something like what this project is doing:

/ Michael /

Mar 5, 2010 at 8:50 PM

I realize I may be asking a little much to have it fix Javascripts broken RegEx implementation... I want ahead and just used the app linked above to convert my requirements to a string of explicit Unicode character groups. It makes for one heck of an ugly Regular Expression, but it works...

Mar 5, 2010 at 9:35 PM

This is not really an xVal issue, but more than likely an issue due to the fact that .NET and JavaScript differ in their Regular Expression syntax.  Because of that, the only way I can see getting around this is to create your own custom attribute, as well as a custom provider for xVal on the server which will catch the regex and transform it to the appropriate output when emitting the validation rules in the script.


Mar 5, 2010 at 9:58 PM

Yeah, I kinda gathered that after looking around about Javascript's RegEx engine. Basically, it seems to be hit or miss depending on what browser you're running... Kind of annoying. I guess I could do something like this:


which kind of has the same effect as this monstrosity:


Which is what I am using right now (and does in fact work). I just might be missing a few characters with the shorter one...

/ Michael /