I need to detect if some string contains symbols from a non latin alphabet. Numbers and special symbols like -
, _
, +
are good. I need to know whether there is any non latin symbols. For example:
"123sdjjsf-4KSD".just_latin?
should return true
.
"12333ыц4--sdf".just_latin?
should return false
.
I think that this should work for you:
# encoding: UTF-8
class String
def just_latin?
!!self.match(/^[a-zA-Z0-9_\-+ ]*$/)
end
end
puts "123sdjjsf-4KSD".just_latin?
puts "12333ыц4--sdf".just_latin?
Note that *#ascii_only?* is very close to what you want as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With