我在谷歌上找不到解决方案
这适用于第一个字符
validates :number, format: { with: /\A[2-9]/ }这也适用于第四个角色
validates :number, format: { with: /\A...[2-9]/ }但在我的一生中,我想不出如何将它们合并在一起来验证两者。请帮帮忙
发布于 2020-10-26 05:35:52
使用
validates :number, format: { with: /\A[2-9].{2}[2-9]/m }说明
--------------------------------------------------------------------------------
\A the beginning of the string
--------------------------------------------------------------------------------
[2-9] any character of: '2' to '9'
--------------------------------------------------------------------------------
.{2} any character (2 times)
--------------------------------------------------------------------------------
[2-9] any character of: '2' to '9'发布于 2020-10-23 16:55:46
您可以使用\w\W{2}表示任意2个字符:
/A[2-9][\w\W]{2}[2-9]/https://stackoverflow.com/questions/64492994
复制相似问题