I have the following regex test on a users input:
function validate_form() {
return /^[a-fA-F0-9]+$/.test(document.form.input.value);
}
I the users input failed to meet the criteria, then how would i get an alert put in this code to inform them?
You could replace the
returnstatement with:Alternatively, you could keep your validation function as above, and do:
If you want to show the error message in the document itself, then you could do something like, and replace
alert()above witherror():This assumes that you have an element in your HTML with
id="error"e.g.: