【发布时间】:2018-06-28 00:02:24
【问题描述】:
我正在尝试在我的 ruby 脚本中验证正确的日期输入。
当我运行脚本时,它只会询问日期两次,无论它是否正确。
谁能告诉我哪里出错了?
def get_date(prompt="What is the date of the last scan (YYYYMMDD)")
new_regex = /\A[0-9]{4}[0-1][0-9][0-3][0-9]\z/
print prompt
gets.chomp
if prompt != new_regex
puts "Please enter the date in the correct format"
print prompt
gets.chomp
end
end
【问题讨论】:
标签: ruby regex validation