How to check whether a string contains special character in ruby. If I get regular expression also it is fine.
Please let me know
How about this command in Ruby 2.0.0 and above?
def check_for_a_special_charachter(string) /\W/ === string end
Therefore, with:
!"He@llo"[/\W/].nil? => True !"Hello"[/\W/].nil? => False