Skip to content
Advertisement

Javascript: check if word in input is placed after an other word

I have a question but I can’t find the answer for my problem. Hope you can help me!

Here’s my HTML:

JavaScript

Here’s my Javascript:

JavaScript

Demo

What this script does
I’m making a login form where the input focuses on the second input when a user has typed his email. In my code: it focuses on the next input when the first input detects an ‘@’ symbol and the text ‘.com’.

But here’s the problem
Lets say your email is: ‘john.computer@gmail.com’. My script focuses on the second input after you typed the ‘@’ symbol, because the input already contains ‘.com’ and ‘@’.

My Question
What javascript do I need to add that checks if ‘.com’ is typed after the ‘@’ symbol?

Advertisement

Answer

You could use regex: @.*.com

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement