I am validating a field that can be a telephone number or cell phone number, but when placing the value it accepts me from 7 to 9, I want it to be validated only if it has 7 or 9 characters. How can i fix it?
\d{7,9}
Code
$(document).ready(function () {
var telefono = $("#campo_telefono")
var expreg = /\d{7,9}/;
if (expreg.test(telefono))
alert("El telefono es correcta");
else
alert("El telefono NO es correcta");
});
This expression is valid: only digits from 0 to 9 and between braces ({N, M}) range of number of digits; example: from 7 to 9 digits.
If you need only a number of digits; example: only 7 digits.
If you need number of exact digits; example: only 7 or 9 digits.