(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
return {
validation = function(frame)
local result = true
local id = mw.text.trim(frame.args.id or '')
if mw.ustring.match(id, '^%d+$') then
-- 純數字
if not (string.sub(id, 1, 1) ~= '0' and string.len(id) <= 9) then -- 若id為純數字時,當首位不為0且長度在1-9位時合法。
result = false
end
elseif mw.ustring.match(id, '^[aA][vV]%d+$') then
-- 若id為【av+純數字】(不區分大小寫)時,當且僅當純數字部分首位不為0且長度在1-9位時合法,其餘情況添加分類
if not (string.sub(id, 3, 3) ~= '0' and string.len(id) <= 11) then
result = false
end
elseif mw.ustring.match(id, '4.1.7..$') then
if string.len(id) == 12 then
-- 若id為【BV1】開頭時,當且僅當id長度為12位,且除去【BV1】後的部分均不包含小寫l大寫I、大寫O和數字0時合法。
if not mw.ustring.match(id, '^[bB][vV]1[a-km-zA-HJ-NP-Z0-9]+$') then
result = false
end
elseif string.len(id) == 10 then
-- 若id為【1】開頭時,當且僅當id長度為10位,且除去【1】後的部分均不包含小寫l大寫I、大寫O和數字0時合法。
if not mw.ustring.match(id, '^1[a-km-zA-HJ-NP-Z0-9]+$') then
result = false
end
elseif string.len(id) == 9 then
-- 若id不滿足上述四種情況時,當且僅當id長度為9位,且不包含小寫l大寫I、大寫O和數字0時合法。
if not mw.ustring.match(id, '^[a-km-zA-HJ-NP-Z0-9]+$') then
result = false
end
else
result = false
end
else
result = false
end
if result then
return ''
else
return frame:expandTemplate {title = 'ArticleCategory', args = {'Bilibili視頻ID錯誤'}} ..
'<span class="BilibiliVideoIDValidatorArgument" style="display: none;">' ..
frame.args.id .. '</span>'
end
end
}