Check whether a string matches a regex in JS

后端 未结 11 2173
余生分开走
余生分开走 2020-11-22 12:02

I want to use JavaScript (can be with jQuery) to do some client-side validation to check whether a string matches the regex:

^([a-z0-9]{5,})$
11条回答
  •  萌比男神i
    2020-11-22 12:34

    Here's an example that looks for certain HTML tags so it's clear that /someregex/.test() returns a boolean:

    if(/(span|h[0-6]|li|a)/i.test("h3")) alert('true');
    

提交回复
热议问题