, ... . Regex - , . nqueens. ( , , .)
function valid(n) {
return (n.length > 3
&& n.match(/^[a-z]/i)
&& n.match(/[a-z0-9]$/i)
&& !n.match(/[._-]{2}/)
}
Now imagine that you allow only one thing., _ Or - of everything (maybe I misunderstood the initial requirements of shrug); which is easy to add (and visualize):
&& n.replace(/[^._-]/g, "").length <= 1
And before someone says “which is less effective,” go through it in the intended use. Also note: I have not given up using regexes completely, they are wonderful things.
user166390
source
share