ruby-on-rails – 仅验证数字
发布时间:2020-12-16 22:56:29 所属栏目:百科 来源:网络整理
导读:在我的一个rails模型中,我有:only_integer验证: validates :number,presence: true,numericality: { only_integer: true } 此验证还允许输入82938434和-signs等输入. 我应该使用哪种验证来仅允许输入而不使用数字? 解决方法 just_integer的 documentation
在我的一个rails模型中,我有:only_integer验证:
validates :number,presence: true,numericality: { only_integer: true } 此验证还允许输入82938434和-signs等输入. 我应该使用哪种验证来仅允许输入而不使用数字? 解决方法
just_integer的
documentation提到了这个正则表达式:
/A[+-]?d+z/ 这意味着你可以使用: validates :number,format: { with: /Ad+z/,message: "Integer only. No sign allowed." } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |