I am currently using this script to validate whether a field is empty or not. The script works well for me, but I would like to add a condition that the field must contain at least 10 digits (numbers). If it doesn't meet this requirement, I want to display an error message as shown in the script. Can anyone help me figure out what needs to be added to the code below?
function checkIfBlank() {
var errorMessage = "";
if (document.getElementById('phoneNumber').value == "") {
errorMessage += "Your phone number must contain 10 digits.";
document.getElementById('phoneNumber').style.borderColor = "red";
}
if (errorMessage != "") {
$(".error-messages").text(errorMessage).fadeIn();
return false;
}
}