0

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'?

1 Answer 1

1

.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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i'll do a quick test and let u knw :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.