i am trying to validate phone number length using jquery, when user start typing itself it should display, i did the following code:
function validatePhone(phone) {
if (phone.value.length <= 10 && phone.value.length >= 5) {
let
var = 'Yes';
return var;
} else {
let
var = 'No';
return var;
}
}
function validate() {
let result1 = $("#result1");
let phone = $("#phone").val();
result1.text("");
if (validatePhone(phone)) {
result1.text(var);
result1.css("color", "green");
}
return false;
}
jQuery(function($) {
$("#phone").on("input", validate);
});
<input type="number" class="form-control" id="phone" name="phone">
<span class="label">Phone Number<span style="color:red">*</span> <span id="result1"></span></span>
however this doesnt work, can anyone please tell me what is wrong in here, thanks in advance