The code copy is as follows: $(function(){ var str="sunny,woo"; var seer=new RegExp(','); if(sear.test(str)) { alert('Yes'); } var tag=','; if(str.indexOf(tag)!=-1) { alert('Yes'); } });