I have multiple input fields with different values. I can edit them but cannot be empty (if empty show an alert). When I am editing if I edit them with blank spaces i used trim to not allow that.But,I am able to edit the input with more spaces at the start and end with a word in between.I don't need this.
How to achieve the following ?
a)Should not start with space.
b)No spaces after the word,if i have one word.
<input type="text" class="selector" value="new">
<input type="text" class="selector" value="old">
<input type="text" class="selector" value="newest">
<input type="text" class="selector" value="oldest">
<input type="text" class="selector" value="older">
$('.selector').on('blur',function () {
var current_value = $.trim($(this).val());
$(this).attr('value',current_value);
console.log(current_value);
if ($('.selector[value="' + current_value + '"]').not($(this)).length > 0 || current_value.length == 0 ) {
$(this).focus();
alert('You cannot use this');
}
});
My fiddle here