Use regex.test()
if all you want is a boolean result:
console.log(/^([a-z0-9]{5,})$/.test('abc1')); // false
console.log(/^([a-z0-9]{5,})$/.test('abc12')); // true
console.log(/^([a-z0-9]{5,})$/.test('abc123')); // true
…and you could remove the ()
from your regexp since you’ve no need for a capture.
Related Contents:
- Return positions of a regex match() in Javascript?
- Javascript + Regex = Nothing to repeat error?
- Jquery Value match Regex [duplicate]
- What does the “Nothing to repeat” error mean when using a regex in javascript?
- regular expression to match exactly 5 digits
- split string only on first instance of specified character
- Why does a RegExp with global flag give wrong results?
- RegEx for Javascript to allow only alphanumeric
- Replace multiple strings with multiple other strings
- Check if string begins with something? [duplicate]
- Javascript replace with reference to matched group?
- Is there a version of JavaScript’s String.indexOf() that allows for regular expressions?
- Remove insignificant trailing zeros from a number?
- Switch statement for string matching in JavaScript
- How can I strip all punctuation from a string in JavaScript using regex?
- Replace all non alphanumeric characters, new lines, and multiple white space with one space
- Regex using javascript to return just numbers
- Trim spaces from start and end of string
- javascript regex – look behind alternative?
- What is the meaning of the ‘g’ flag in regular expressions?
- Why does Javascript’s regex.exec() not always return the same value? [duplicate]
- JavaScript Regular Expression Email Validation [duplicate]
- Case insensitive regex in JavaScript
- Regex to Match Symbols: !$%^&*()_+|~-=`{}[]:”;’?,./
- Is there a difference between /\s/g and /\s+/g?
- escaping question mark in regex javascript
- Split the sentences by ‘,’ and remove surrounding spaces
- Javascript regular expression: remove first and last slash
- why does my javascript regex.test() give alternating results [duplicate]
- Javascript date regex DD/MM/YYYY
- Remove line breaks from start and end of string
- How can I replace newlines/line breaks with spaces in javascript?
- javascript regex for password containing at least 8 characters, 1 number, 1 upper and 1 lowercase [duplicate]
- Javascript Regular Expressions – Replace non-numeric characters
- How to remove the extra spaces in a string?
- javascript url-safe filename-safe string
- Remove everything after last backslash
- JavaScript regular expressions and sub-matches
- Can I use a regular expression in querySelectorAll?
- Range out of order in character class in javascript
- String.Replace only replaces first occurrence of matched string. How to replace *all* occurrences?
- How to prevent Javascript injection attacks within user-generated HTML
- Javascript Regexp – Match Characters after a certain phrase
- Replacing accented characters with plain ascii ones [duplicate]
- How to wrap part of a text in a node with JavaScript
- JS regex: replace all digits in string
- Javascript regex for matching/extracting file extension
- What does regex’ flag ‘y’ do?
- Get index of each capture in a JavaScript regex
- Regex for replacing a single-quote with two single-quotes