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]+$/
Enable the submit button in the input form. If the <valid/> element value is false, set the HTML of the validationMessage div element in Catalog ID field row to "Catalog Id is not Valid". Disable the submit button, and set the values of the other input fields. Next, run the Ajax application in JDeveloper 10.1.
Just for information you should not validate User code on the clientside. Always treat input from the client as evil
I changed the regex so that the min length (username.length < 4
) of the Username is included
function username_check() {
var username = $('#warden_id').val();
// if / else has been turned
if (username.match(/^[a-zA-Z\s]{4,}$/)) {
...
} else {
$('#warden_id').css('border', '1px #CCC solid');
$('#tick').hide();
}
...
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With