After extensive research and tutorials, I am still unable to figure out what is going wrong with my work.
I have a button that looks like this:
Despite Stack Overflow causing some trouble for me, please ignore the missing class as it is there. This is not the issue where I am stuck.
When the button is clicked, it triggers a JavaScript code like this:
$(document).on("click", "#create_account", function(evt)
{
/* This code is not mine; I found it in an online tutorial and it works on JSFiddle, so I know this isn't the problem */
function phonenumber(inputtxt)
{
var phoneno = /^\d{10}$/;
if(inputtxt.value.match(phoneno))
{
return true;
}
else
{
alert("Not a valid Phone Number");
return false;
}
}
});
I suspect the reason why this isn't working is because I am not calling that specific function to run. However, after some tests, I do know that it is hitting the onclick aspect of it.
My goal is to validate the phone number to be 10 digits (for now). I have set the input type as text with the ID "input_phone". I plan to modify this further for more than just 10 numbers later on, but I am currently struggling to execute this function and trigger that alert message.
Thank you in advance for any tips or help!