Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a string has at least 6 characters in it in javascript?

I have a variable, email.

"Check to see if the email value property is at least 6 characters in length"

How do I do that? I dont even know what to google. I tried searching "require certain amount of characters in a string javascript" and couldnt find anything.

The closest thing I could find was to use indexOf. But still I couldnt find any examples using indexOf.

Heres what I have.

if (email != '' && email.indexOf(5) && email.indexOf("@")) {

I put 5 because one example I found was an array so I wasnt sure if it applied to this too. The other indexOf is to check if the string also contains @

like image 699
Kevin.B Avatar asked Aug 31 '25 21:08

Kevin.B


1 Answers

You can do it as:

if(email != null && email.length > 5){
    // Your code...
}
like image 161
Viswanath Donthi Avatar answered Sep 03 '25 09:09

Viswanath Donthi