You can do both in the same regular expression (guessing zip code - numbers).
('1234567').match(/^\d{5,}$/) // ['1234567']
('1234').match(/^\d{5,}$/) // null
('12 34').match(/^\d{5,}$/) //null
('123 4567').match(/^\d{5,}$/) //null
therefore instead of:
if((val.length >= 5) && (*******)){
}
using:
if(val.match(/^\d{5,}$/)) {
}
source
share