In this lesson, we're going to check to see if the input is a valid email.
So this is where we can check.
And just as we've got the condition over here, that's checking to see if our length and our required
fields have a length, we can add in another condition now to check to see if the temp name.
So remember, this is the name of the input field and if it's equal to email and if it is that we can
run our email check.
So we need to set up an expression to do that.
We can set up an expression.
So it's going to be a regex expression.
And then also we can check to see the result by running a test on it.
So calling this result and we can take that expression testing, the result of the of the expression
and the variable that we can pass in is going to be the name and for now will console log out the value
of result so we can see that and take a closer look at it.
So need to create an expression.
So there's a tool that I like to use in order to keep regex, and that's regg exer dot com.
And I'm going to create an email address so we know that email addresses can have multiple characters
and it can have digits.
It underscores there's a number of different things that can be included as well as dots.
So what we want to do is identify anyone that matches a particular pattern.
So taking a look at A to Z, we're going to look through all of the contents and we're going to see
which one matches this pattern.
And we're also going to look for lowercase A to Z.
So that's returning back.
All of the characters also wanted to include zero to nine.
So in case our email address has some numbers in there, that's going to be valid as well.
And even if the domain has some digits in there, that's going to be valid as well.
Also, the dots are valid as well as underscore.
So if our email address has an underscore, once again, this is valid.
So we're looking to see on return back all of that information.
And also the other one that's valid are dashes.
So anything that matches this pattern, we want to return back.
So we want to add to it.
So we want to make sure that it has an at symbol next.
So that's the next thing that we're looking for.
And then for the domain name, it can also have a pattern that we're looking for.
And the pattern is almost going to be the same thing that we just looked at, where we've got the letters,
the numbers, the dot, the underscore, the dash.
So all of those are valid.
And we also need to check to see all of the characters after that.
And we're looking for a dot.
So any of those ones that have a dot and we know that every email address is going to have a domain
name and all domain names have a dot in it.
So I sense where we're going to be looking for that dot so we can take the same thing and then the parent
domain and the parent domain.
So we're not looking for any additional dots.
We're not looking for any underscore or dashes within the main domain name.
So we see that we're returning back the email address.
So this is a good way to validate and simply validate your email addresses to make sure that you're
getting a valid email address and a great place to build your regular expressions.
So now that we able to select out the email address from all of the other text, that means that we
can use it as an expression.
So you can bring that expression into our project.
And the way that we do that is with the slash and then the other, so that when we refresh, we're going
to check to see all of the email addresses and what's being returned back is it's false.
So if we take that email address that we just created here within the regular expression and if we post
this in, if we do sign up, we see that we're returning back a value of true.
So that means that this email address passed out and we can also return back an error if it doesn't
pass the check.
So if result is not true, if it's false, then what we want to do is we want to pass over an error
message and say that the email field is not valid.
So we're passing over to that same function where we've got add error and we can write invalid and you
can build out any number of errors and checks as needed.
There's other things, too, that I wanted to add in.
So before we continue, let's add in a variable for error and we're set that to false.
So that basically means that there's no errors.
But if we do return back any errors, we set it to true.
And that means that this is our way to kind of stop the submission.
If there's no errors that are going to get registered within any of these conditions that we know that
the email and the form should submit.
So now we're checking to see email addresses and we can also do a similar thing for.
The password, if we want letters, numbers and characters, so you had to do that in the upcoming lesson,
so this is the more complex one building at the regular expression to check, to see if emails and if
there's valid emails.
So go ahead and add this one into your project.
And coming up next, we'll do a check on the password feel to check to see its length as well as we're
going to check to see if it's got the right characters.
So go ahead and add that into your project.