Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a regex expression saying 'and NO whitespaces'?

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

like image 413
Nasir Avatar asked Sep 19 '25 10:09

Nasir


1 Answers

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.

like image 91
Kobi Avatar answered Sep 22 '25 03:09

Kobi