40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const signinForm = document.querySelector('form[action="/signin"]');
|
|
if (signinForm) {
|
|
signinForm.addEventListener('submit', (event) => {
|
|
const password = document.getElementById('password').value;
|
|
const regex = /^[A-Za-z0-9]+$/;
|
|
|
|
if (!regex.test(password)) {
|
|
event.preventDefault();
|
|
alert('密码只能包含大小写字母和数字,不允许出现其他符号。');
|
|
}
|
|
});
|
|
}
|
|
|
|
const signupForm = document.querySelector('form[action="/signup"]');
|
|
if (signupForm) {
|
|
signupForm.addEventListener('submit', (event) => {
|
|
const password = document.getElementById('password').value;
|
|
const confirmPassword = document.getElementById('confirm-password').value;
|
|
const captcha = document.getElementById('captcha').value;
|
|
const lengthRegex = /^.{6,16}$/;
|
|
const alphanumericRegex = /^(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]+$/;
|
|
|
|
if (!lengthRegex.test(password)) {
|
|
event.preventDefault();
|
|
alert('密码必须是6到16个字符之间。');
|
|
} else if (!alphanumericRegex.test(password)) {
|
|
event.preventDefault();
|
|
alert('密码必须包含字母和数字,不允许出现其他符号。');
|
|
} else if (password !== confirmPassword) {
|
|
event.preventDefault();
|
|
alert('密码和确认密码不匹配。');
|
|
} else if (!captcha) {
|
|
event.preventDefault();
|
|
alert('请填写验证码。');
|
|
}
|
|
});
|
|
}
|
|
});
|