regex for alphanumeric and allow an additional character also
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.
精彩评论