开发者

regex for alphanumeric and allow an additional character also

开发者 https://www.devze.com 2023-01-23 11:27 出处:网络
How could I allow a string to match alphanumeric characters and a comma cha开发者_JS百科racter And have the input be a minimum of 6 and 50 max;

How could I allow a string to match alphanumeric characters and a comma cha开发者_JS百科racter And have the input be a minimum of 6 and 50 max;

Now, it matches nothing, with or without the comma in it?

test = "dam, Amsterdam";
if( test.match(/^\w{6,50}\,$/) ){

thanks, Richard


/^[\w, ]{6,50}$/

I've created a character class (the square brackets) and added comma and space. The regex space is a way to allow the space after the comma in the input. Note that it's never necessary to escape a comma in a regex.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号