8 AnswersNew Answer
For example with Regular Expressions: var password = "My3Password_"; var patt = /\b[a-z]/i; var res = patt.test(password); // res = true
For example: string.charAt(i) and i = 0 where string is the password, that means: string.charAt(0)
Ja Play In your regex example, you have an extra unwanted escape character \ after the b in your patt string.
Ja Play You say it worked but, for me, it gave False as an output. 🤔
Ja Play Also, not wanting to pick holes in your solution, but var password = "[email protected]"; var patt = /\b[a-z]/i; also returns true. You can simply use an anchor to search only the start of the string. var patt = /^[a-z]/i
In the beginning I tested with \w and then replaced with [a-z] and forgot to remove \ - but it worked. Thanks Russ - already removed.
Russ there isn't just one way of doing it.
Ja Play I completely agree and I'm sorry if I upset you - that really wasn't my intention. The reason for my last comment was that I wanted to let OP be aware of a solution that I felt was reliable. I felt that your code didn't necessarily return the correct answer, and my comment contained an example where your code returned true for starting with a letter, when it wasn't the case. I also feel that I did pick my words carefully, by saying "You can simply use an anchor..." rather than "You need to..." or "You should...". I hoped that that wording conveyed the idea that this was just an option, not the only way. Again, I'm really sorry if I upset you.