1

I have this regex in my model:

/^(?:[^\W_]|\s|[\._@-])*$/u

I want add to this regex this special char:

ñáéíóú

I would like to know how add other charset from other languajes, chino, japanesse, indian...etc. Thank you.

hyperrjas
  • 10,666
  • 25
  • 99
  • 198

1 Answers1

5

I don't know if Ruby understand that, but you should use unicode properties like:

/^[\p{L}\s\p{N}._@?¿!¡€-]+$/

where

\p{L}   : any unicode letter
\p{N}   : any unicode number
Toto
  • 89,455
  • 62
  • 89
  • 125
  • Yes works fine :D. Its possible add to this regex this characters **?¿!¡€,** Thank youuu! – hyperrjas Feb 18 '12 at 11:27
  • I get error **invalid multibyte char (US-ASCII)** with this regex :( `/^[\p{L}\s\p{N}._@?¿!¡€-]+$/` – hyperrjas Feb 18 '12 at 11:39
  • @hyperrjas: I don't know Ruby but I've found that : http://stackoverflow.com/questions/1739836/invalid-multibyte-char-us-ascii-with-rails-and-ruby-1-9 – Toto Feb 18 '12 at 11:42
  • Wooow Thank you now it does works fine :D write `# encoding: utf-8` and works fine :D Thank you @M42 and @apneadiving – hyperrjas Feb 18 '12 at 11:48