JS代码修改:限制输入字符为数字、下划线和大小写字母,最大长度255字符
<script>
function checkWeight() {
var maxAttempts = 10;
var today = new Date();
today.setHours(0, 0, 0, 0);
var expires = new Date(today.getTime() + (24 * 60 * 60 * 1000));
var attempts = getCookie('attempts');
if (attempts === null) {
attempts = 0;
}
if (attempts >= maxAttempts) {
alert('免费用户只能查询' + maxAttempts + '次,请明天再来,或者找管理员赞助吧');
return;
}
var url = document.getElementById('input-link').value.trim();
var pattern = /^[a-zA-Z0-9_]{1,255}$/;
var match = url.match(pattern);
if (match !== null) {
var newUrl = 'dy.php?url=' + match[0];
location.href = newUrl;
setCookie('attempts', ++attempts, expires);
} else {
alert('输入的链接格式不正确,请重新输入。');
}
}
function getCookie(name) {
var pattern = new RegExp('(?:(?:^|.*;)\s*' + name + '\s*\=\s*([^;]*).*$)|^.*$');
return decodeURIComponent(document.cookie.replace(pattern, '$1')) || null;
}
function setCookie(name, value, expires) {
document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires.toUTCString() + '; path=/';
}
</script>
原文地址: https://www.cveoy.top/t/topic/mkY8 著作权归作者所有。请勿转载和采集!