# Unicode in Forms & Ruby Regex

**URL:** <https://www.ruby-forum.com/t/unicode-in-forms-ruby-regex/121736>\
**Category:** Rails\
**Created:** [November 30, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/unicode-in-forms-ruby-regex/121736 "2007-11-30T12:04:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 30, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/unicode-in-forms-ruby-regex/121736/1 "2007-11-30T12:04:02Z")

</div>

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.’-\]\*?$/

So, what’s the secret to using unicode character ranges in Ruby regex  
or Rails validations?

It also seems to fail with full \x0000 numbers, is there limit at \xFF?

–  
def gw  
acts\_as\_n00b  
writes\_at(www.railsdev.ws)  
end

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 30, 2007, 11:38pm UTC](https://www.ruby-forum.com/t/unicode-in-forms-ruby-regex/121736/2 "2007-11-30T23:38:15Z")

</div>

On Nov 30, 2007, at 3:03 AM, Greg W. wrote:

> /^[\x41-\x5A\x61-\x7A.’-\]\*?$/
> 
> So, what’s the secret to using unicode character ranges in Ruby regex  
> or Rails validations?
> 
> It also seems to fail with full \x0000 numbers, is there limit at  
> \xFF?

OK, so now that I’ve come to recognize that unicode support in Ruby  
totally blows, are there any hacks out there anywhere?

I want to:

- allow a web site visitor to enter the “usual” extended latin  
characters into a web form

- use a regular expression (this is where the crux of the problem is)  
to ensure that all characters in the string are allowed

- save that data to MySQL (utf8)

- display it with the correct characters in tact

It’s no problem to capture the text store it & redisplay it, but  
without filtering/validation–which of course is not acceptable.

Is anyone doing white listed character validations like this?

–  
def gw  
acts\_as\_n00b  
writes\_at(www.railsdev.ws)  
end
