Reputation: 146
I have the following code:
var isvalid = [];
function namevalidation(){
var checkname = $("#first-name").val();
var namevalid = new RegExp("(^[a-zA-Z'-]+$)");
var name_error = $("error");
if(checkname.match(namevalid)){
$(name_error).css("display","block");
if($.inArray('name', isvalid) == -1){
isvalid.push('name');
}
}else{
$(name_error).css("display","none");
if($.inArray('name', isvalid) > -1){
isvalid.splice("name",1);
}
}
}
I do not know the position of the string inside the array, as i would have many similar functions for other inputs. Based on the code above how do i remove the string 'name' from the array 'isvalid'?
Upvotes: 0
Views: 39
Reputation: 388316
.splice() takes the index of the item as the first argument, so try
var index = $.inArray('name', isvalid);
if (index > -1) {
isvalid.splice(index, 1);
}
Upvotes: 1