I am trying to find for the string of the format abc1234. I can compare character taking at each index whether is alpha or numeric and get the result. Instead wrote for a pattern match but couldn’t succeed. Could some one know me where I am going wrong ?
var clid = "mxv4013" ;
if(clid.match("/[a-z]{3}(?=[0-9]{4})/i") != null){
alert("success") ;
}
Thanks.
You don’t need the quotes, JavaScript has regex literals:
You can also remove the
!= nullcheck –matchwill return a true value on success and a falsy value on fail. In addition, the look-ahead is a little strange, you can use/[a-z]{3}\d{4}/i, or, to validate the whole string and avoid partial matching,/^[a-z]{3}\d{4}$/i.