I'm using jqBootstrapValidation.js ( http://reactiveraven.github.io/jqBootstrapValidation/ ) and I want to check if a username that I choose is already existing.
I loaded all Usernames in an array:
$array = array("User1","User2",...);
and now I want to check if the username already exists while typing it in an input field and want to add the alert in the jqBootstrapValidation help-blocks.
try something like this if your user array is javascript array
javascript code
function checkuser_callback_function($el, value, callback) {
var $array = new Array("User1","User2");
var valid = false;
if($array.indexOf(value) == -1){
valid = true;
}
callback({
value: value,
valid: valid,
message: "User present."
});
}
HTML code
<input type="text" data-validation-callback-callback="checkuser_callback_function" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.