Currently, I am using JavaScript and AJAX to validate a registration form. The functions restrict(elem) and checkusername() are both working as intended. When the AJAX passes the checkusername variable to PHP, it checks if the username exists and displays a message indicating whether the username is available or taken. However, other fields are not being validated. Below is my JavaScript code for validation on the client-side before sending data to PHP:
function restrict(elem) {
var tf = _(elem);
var rx = new RegExp;
if (elem === "email") {
rx = /[' "]/gi;
} else if (elem === "username") {
rx = /[^a-z0-9]/gi;
} else if (elem === "mobileNumber") {
rx = /[0-9]/g;
}
tf.value = tf.value.replace(rx, "");
}
function emptyElement(x) {
_(x).innerHTML = "";
}
function checkusername() {
// Code for checking username
}
function signup() {
// Code for signing up
}
Here is my form where users can input their information:
<form name="signupform" id="signupform" onsubmit="return false;">
// Form inputs for username, email, password, etc.
</form>