Regex to check alphanumeric string in ruby

前端 未结 6 1935
生来不讨喜
生来不讨喜 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:06

    Great answers above but just FYI, your error message is because you started your regex with a double quote ". You'll notice you have an odd number (5) of double quotes in your method.

    Additionally, it's likely you want to return true and false as values rather than as quoted strings.

提交回复
热议问题