Hi, I would like to check the name a user enters. If it is already taken the code will give this message:
if (names.findOne({name:name.value})) {
template.$('.errorPopUp').text("Name already taken.")
return;}
This works in a primitive way - however, it’s not case-sensitive. So being give a name “test”, it would go through with a new name being “Test”. Could someone explain to me, how to make this query case sensitive?
names.findOne({name: new Regexp(name.value, 'i')})
basically use use an insensitive regular expression, if you aren’t sure where test appears in the string, use ‘ig’ to search it (g)lobally in the string.
You may want to learn more about how regex works. Adding the g flag would find timo if searching tim. It would also find things like asdftimo if adding the g flag.
You could do ^tim.* To find things that start with tim and have any amount of characters after but then again there are a ton of use cases that you will know. Try using the site regex101.com to experiment.
But as far as I understood I only added the i-flag? I mean, when I test it with the same condition on regex101, it’s not giving me any result. Thats why I’m confused.
I had the i-flag tested on regex101 and being “Kuroki” the string it didn’t match with “Kuro”
for this it doesn’t match because it isn’t using the g.
You need to learn regex a little more, and as a programmer/developer I suggest you learn it a lot more since it is very powerful and can do a lot more.