请引导我使用正则表达式,该正则表达式接受包含+
,-
,(
,)
,空格和数字的任何字符串。例如,89+98+67-45+(56+90)+()
是可以接受的。
我有以下正则表达式
validates :number, format: { with: /\A(?:[- +()0-9])\z/,
message: I18n.t('global.errors.phone_format')}
但它不起作用。
答案 0 :(得分:2)
你刚忘记了一个转发器:
SELECT * FROM TRNS_RATE_DETAILS
WHERE EFFECTIVEDATE >= @STARTDATEOFMONTH
AND ENDDATE <=@LASTDATEOFMONTH
感谢@Stefan,这个小组是多余的:
{{1}}
答案 1 :(得分:0)
答案 2 :(得分:0)
@sawa unfortunately deleted his answer, but it was perfectly fine:
re = /[^+() \d-]/
"398hjfj" !~ re # => false
"89+98+67-45+(56+90)+()" !~ re # => true
Since this is a negative match, it has to be used with the format validator's :without
option:
validates :number, format: { without: /[^+() \d-]/ }