ruby - how to return true or false when a string contains any letters A-Z or a-z? -


i familiar how check if string contains substring, , familiar how check if single letter number or letter, how go checking string letters?

def letters?(string)   # do here? end  # string '111' '1a2' 'ab2589a5' etc...  string = '1a2c35' if letters?(string) == true   # if string has letters else   # else if doesnt end 

i think, can try it:

def letters?(string)    string.chars.any? { |char| ('a'..'z').include? char.downcase } end 

if don't wanna use regexp. method return true if there letters in string:

> letters? 'asd'  => true  > letters? 'asd123'  => true  > letters? '123'  => false  

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -