.
initializers/constants.rb
letters = ("a".."z").collect
numbers = ("1".."9").collect
symbols = %w[! @
FILTER = letters + numbers + symbols
And then he just checked to see if he was in my filter:
if !FILTER.include?(c)
else
end
You can also check the Unicode value, but you need to know the range or specific values. I did it with Chinese characters, so I got my values. I will send the code simply to give you an idea:
def check(char)
char = char.unpack('U*').first
if char >= 0x4E00 && char <= 0x9FFF
return true
end
if char >= 0x3400 && char <= 0x4DBF
return true
end
if char >= 0x20000 && char <= 0x2A6DF
return true
end
if char >= 0x2A700 && char <= 0x2B73F
return true
end
return false
end
Of course you need to know the specific meanings.
source
share