I'm developing a system and want to do validations through functions.
I have the checkUsername
function that does query in the database to return me whether or not it can register with that username.
And then you have other functions to check other things like checkEmail
. How to apply these functions one after another in a form submit?
Examples of functions I'm using:
function checkUsername(username){
$("#username").focusout(function() {
var username = $("#username").val();
var pattern = /^[a-z0-9_-]{3,16}$/;
if (pattern.test(username)) {
var Urlverificadora = 'action=verificar_username&username='+username;
$.ajax({
type : 'POST',
data : Urlverificadora,
url : painel+'checkUser.php',
success: function(responseText){ // Get the result and asign to each cases
if(responseText == 0){
$("#username").css("border", "2px dashed green");
} else if(responseText > 0){
$("#username").css("border", "2px dashed red");
} else{
alert('Entre em contato com o administrador.');
} //success
}
}); //ajax
} else {
$("#username").css("border", "2px dashed red");
};}
)};