再次回到另一个绝对初学者的问题。我正在验证一个表单,并且我希望将文本输入限制为 2 个以上且少于 15 个字符。我试过了:
function validateForm(formElement) {
var valid = true;
if (formElement.first_name.value.length < 2) return focusElement(formElement.first_name, 'Please enter a First Name that is more than 2 characters long.');
if (formElement.first_name.value.length > 15) return focusElement(formElement.first_name, 'Please enter a First Name that is less than 15 characters long.');
也
if (formElement.first_name.value.length < 2 && formElement.first_name.value.length > 15) return focusElement(formElement.first_name, 'Please enter a First Name that is more than 2 and less than 15 characters long.');
两者都会导致错误。我怎样才能做到这一点?