Right now i am using ajax to get the value from input field on key press and match it with the data in mysql,if the data is unique then it will make the border green and mark tick else red border and cross. now i want to add regex to validate the input and restrict it.
function username_check() {
var username = $('#warden_id').val();
if (username == "" || username.length < 4) {
$('#warden_id').css('border', '1px #CCC solid');
$('#tick').hide();
} else {
jQuery.ajax({
type: "POST",
url: "check.php",
data: 'username=' + username,
cache: false,
success: function (response) {
if (response == 1) {
$('#warden_id').css('border', '1px #C33 solid');
$('#tick').hide();
$('#cross').fadeIn();
} else {
$('#warden_id').css('border', '1px #090 solid');
$('#cross').hide();
$('#tick').fadeIn();
}
}
});
}
regex i want to use to validate data
/^[a-zA-Z\s]+$/