This is mostly a Ruby thing, and partly a Rails thing.
I’m expecting a validate_format_of with a regex like this
/^[a-zA-Z\xC0-\xD6\xD9-\xF6\xF9-\xFF.’-\ ]*?$/
to allow many of the normal characters like ö é å to be submitted via
web form.
However, the extended characters are being rejected.
This works just fine though (which is just a-zA-Z)
/^[\x41-\x5A\x61-\x7A.’-\ ]*?$/
It also seems to fail with full \x0000 numbers, is there limit at \xFF?
Some plain Ruby tests seem to suggest unicode characters don’t work at
all??
p ‘abvHgtwHFuG’.scan(/[a-z]/)
p ‘abvHgtwHFuG’.scan(/[A-Z]/)
p ‘abvHgtwHFuG’.scan(/[\x41-\x5A]/)
p ‘abvHgtwHFuG’.scan(/[\x61-\x7A]/)
p ‘aébvHögtÃ¥wHÃ…FuG’.scan(/[\xC0-\xD6\xD9-\xF6\xF9-\xFF]/)
[“a”, “b”, “v”, “g”, “t”, “w”, “u”]
[“H”, “H”, “F”, “G”]
[“H”, “H”, “F”, “G”]
[“a”, “b”, “v”, “g”, “t”, “w”, “u”]
["\303", “\303”, “\303”, “\303”]
So, what’s the secret to using unicode character ranges in Ruby regex
(or Rails validations)?
–
def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end