diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 2980f2ed2..497c26cae 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -4,4 +4,5 @@ module CustomRegexp LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/ NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/ PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{8,16}\z/ + URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/ end \ No newline at end of file diff --git a/app/models/live_link.rb b/app/models/live_link.rb index cd6655c30..5dcfaf3d3 100644 --- a/app/models/live_link.rb +++ b/app/models/live_link.rb @@ -4,7 +4,7 @@ class LiveLink < ApplicationRecord has_many :tidings, as: :container, dependent: :destroy - validates :url, presence: true + validates :url, presence: true, format: { with: CustomRegexp::URL, message: "必须为网址超链接" } validates :description, length: { maximum: 100, too_long: "不能超过100个字符" } def op_auth?