I downloaded this endsWith function –
String.prototype.endsWith = function(suffix) {
return this.match(suffix+"$") == suffix;
}
and am trying to use it to verify a form input with
function validator(form){
var input = form.user.value;
if(input.endsWith("vdr")) {
if(input != ""){
$('#userb').fadeOut("fast");
$('#userk').fadeIn("fast");
}
}else{
$('#userk').fadeOut("fast");
$('#userb').fadeIn("fast");
}
}
I am using jQuery to show a div. The problem is it doesn’t do anything, and since it works without the check for the endsWith(), it is probably that function that is causing trouble. Why is this not working? Are there any alternatives to the endsWith that will work?
String.matchreturns an array of matches. Try something like this: