Using regular expressions to check length?

Is it possible to use regular expressions to specify the minimum length for a string? I currently have the expression [1]+$, to just accept letters and numbers. I would like to ensure the string has a least 6 characters (numbers or letters) within it.

Thanks for any help

Andrew


  1. a-zA-Z0-9 ↩︎

Depending on what implementation of regex you’re using, you can specify ranges with curly braces. eg
{6} – exactly 6
{6,} – at least 6, no upper limit
{6,10} – at least 6, no more then 10

So is this right:
[1]+${6,}
???

Cheers

Andrew


  1. a-zA-Z0-9 ↩︎

No, this is:
/[1]{6,}$/

This checks for 6 or more alphanumeric characters (note the anchor at the end as well…if that’s not there, you can have non-alpha characters in your 7th character or higher


  1. a-zA-Z0-9 ↩︎

Hi I already have a regex for checking email addresses. How do I ensure that the entire string is 8 characters or more? This is what I have now

[1][\w\.-][a-zA-Z0-9]@[a-zA-Z0-9][\w\.-][a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$


  1. a-zA-Z ↩︎