Regex to check alphanumeric string in ruby

前端 未结 6 2028
生来不讨喜
生来不讨喜 2021-02-19 21:40

I am trying to validate strings in ruby. Any string which contains spaces,under scores or any special char should fail validation. The valid string should contain only chars a-z

6条回答
  •  情深已故
    2021-02-19 22:05

    No regex:

    def validate(str)
      str.count("^a-zA-Z0-9").zero?  # ^ means "not"
    end
    

提交回复
热议问题