I was wondering how I would write a regex expression which says 'and NO whitespaces'.I need to implement this into the following if statement, see below:
$('#postcode').blur(function(){
var postcode = $(this), val = postcode.val();
if((val.length >= 5) && (*******)){
postcode.val(val.slice(0, -3)+' '+val.slice(-3)).css('border','1px solid #a5acb2');
}else{
$(this).css('border','1px solid red');
}
});
Any help is greatly appreciated, Thanks
Try this:
&& (!val.match(/\s/))
match
return null
if there are no spaces (or at least one space), so you can use it as a condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With