It seems like the solution to your issue lies in escaping those dashes within your regex pattern. However, there may still be some additional adjustments needed before your code passes all linting tests.
Despite that, the provided code is successfully passing linting checks, and the regex validation remains effective when tested on regex101.com (credit goes to torazburo).
/*jslint browser:true */
/*global window */
function phoneNumberValidation(inputText) {
"use strict";
var phoneNumberPattern = /[0-9]{3}?[\-.]?[0-9]{3}[\-.]?[0-9]{4}$/;
if (inputText.value.match(phoneNumberPattern)) {
window.alert("Valid Phone Number");
return true;
}
// Previously, JSLint would flag "Unnecessary 'else' after disruption.",
// however, it appears this is no longer a mandatory rule.
window.alert("Not a valid Phone Number");
return false;
}
This raises another inquiry, as highlighted by @torazaburo: How can one validate a phone number in JavaScript?. There are several insightful responses on StackOverflow addressing this query.
Personally, I find this approach quite appealing, even though I haven't personally utilized the library it recommends. Notably, this library is developed by Google and undergoes frequent updates, indicating its reliability over hastily constructed alternatives. Best of luck with your implementation.