When working with vanilla JavaScript to check an HTML input against a regex pattern, things can get tricky. I find myself going back to the parent element to validate the input, and while it works, it's not as elegant as I would like it to be.
Here is the JavaScript code:
input.parentNode.querySelector(':valid')
And here is the HTML input that is being validated:
<input type="tel" id="fos_user_registration_form_mobileNumber" name="fos_user_registration_form[mobileNumber]" required="required" pattern="^0[0|1|2|3|4|5|6|7|9]\d{8}$" maxlength="10">
But is there a better way to achieve this validation?