I want to check input
and want to show error if input is empty or entered continuous space. just one space allowed between words. e.g:
Test ok test
var pattern = /\s\s+/g;
$('a').click(function() {
if ($('input').val().length <= 2 || pattern.test($('input').val())) {
alert('error');
} else {
alert('ok go');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a>check</a>
<input type="text"/>
It seems working, but it have issue, do this to find this issue:
Enter 5 space continuously, then click on check, it alert error
but click again on check, it alert ok
.
should error when user entered more than 2 space continuously.