Meinhard
Meinhard

Reputation: 781

Validate Umlaut in text input with regex

does someone know how to add Umlauts to a regular expression to validate the format for a text input with rails?

I tried this but it breaks rails completely:

validates :first_name, :presence => true, :allow_blank => false, :format => { :with => /\A[a-z A-ZäöüÄÖÜ]+\z/}

Upvotes: 0

Views: 1072

Answers (2)

sailor
sailor

Reputation: 8034

Try this:

validates :first_name, :presence => true, :allow_blank => false, :format => { :with => /\A[[:alpha:]]+\z/}

Upvotes: 3

Viktor Trón
Viktor Trón

Reputation: 8884

This should work, but make sure ruby itself knows what encoding you use in code by adding as the first line (assuming utf-8):

# encoding: UTF-8

let me know if it helps

Upvotes: 1

Related Questions