Is it possible to use regular expressions to specify the minimum length for a string? I currently have the expression +$, 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
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:
+${6,}
???
Cheers
Andrew
No, this is:
/{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
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
[\w\.-][a-zA-Z0-9]@[a-zA-Z0-9][\w\.-][a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$