Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if same value exist in an input box

Is there anyway to check if a similar value exist in an input box

EX:
<input name="user1" value="bla1">
<input name="user2" value="bla2">
<input name="user3" value="bla1">

The verification will trigger when the form is submitted, it will alert the user and add a class to both the input with the similar value.

like image 735
Link Avatar asked Apr 23 '15 00:04

Link


1 Answers

More jQuery'ish

var inputs = $('input');

inputs.filter(function(i,el){
    return inputs.not(this).filter(function() {
        return this.value === el.value;
    }).length !== 0;
}).addClass('red');

FIDDLE

Filters the inputs based on wether or not another input with the same value exists

like image 98
adeneo Avatar answered Oct 02 '22 16:10

adeneo