1
00:00:01,830 --> 00:00:06,560
In this lesson, we're going to check to see if the input is a valid email.

2
00:00:06,870 --> 00:00:08,280
So this is where we can check.

3
00:00:08,400 --> 00:00:15,540
And just as we've got the condition over here, that's checking to see if our length and our required

4
00:00:15,540 --> 00:00:22,350
fields have a length, we can add in another condition now to check to see if the temp name.

5
00:00:22,590 --> 00:00:28,860
So remember, this is the name of the input field and if it's equal to email and if it is that we can

6
00:00:28,860 --> 00:00:30,380
run our email check.

7
00:00:30,600 --> 00:00:33,240
So we need to set up an expression to do that.

8
00:00:33,240 --> 00:00:34,560
We can set up an expression.

9
00:00:34,770 --> 00:00:37,200
So it's going to be a regex expression.

10
00:00:37,200 --> 00:00:42,740
And then also we can check to see the result by running a test on it.

11
00:00:43,140 --> 00:00:51,000
So calling this result and we can take that expression testing, the result of the of the expression

12
00:00:51,150 --> 00:00:57,510
and the variable that we can pass in is going to be the name and for now will console log out the value

13
00:00:57,510 --> 00:01:00,960
of result so we can see that and take a closer look at it.

14
00:01:01,090 --> 00:01:02,960
So need to create an expression.

15
00:01:03,330 --> 00:01:09,660
So there's a tool that I like to use in order to keep regex, and that's regg exer dot com.

16
00:01:09,660 --> 00:01:16,500
And I'm going to create an email address so we know that email addresses can have multiple characters

17
00:01:16,500 --> 00:01:18,080
and it can have digits.

18
00:01:18,090 --> 00:01:23,180
It underscores there's a number of different things that can be included as well as dots.

19
00:01:23,490 --> 00:01:28,250
So what we want to do is identify anyone that matches a particular pattern.

20
00:01:28,500 --> 00:01:34,500
So taking a look at A to Z, we're going to look through all of the contents and we're going to see

21
00:01:34,500 --> 00:01:36,410
which one matches this pattern.

22
00:01:36,690 --> 00:01:39,760
And we're also going to look for lowercase A to Z.

23
00:01:40,050 --> 00:01:41,220
So that's returning back.

24
00:01:41,220 --> 00:01:45,980
All of the characters also wanted to include zero to nine.

25
00:01:45,990 --> 00:01:51,060
So in case our email address has some numbers in there, that's going to be valid as well.

26
00:01:51,270 --> 00:01:55,480
And even if the domain has some digits in there, that's going to be valid as well.

27
00:01:55,980 --> 00:01:59,710
Also, the dots are valid as well as underscore.

28
00:01:59,730 --> 00:02:04,790
So if our email address has an underscore, once again, this is valid.

29
00:02:05,010 --> 00:02:08,430
So we're looking to see on return back all of that information.

30
00:02:08,700 --> 00:02:11,670
And also the other one that's valid are dashes.

31
00:02:11,910 --> 00:02:16,020
So anything that matches this pattern, we want to return back.

32
00:02:16,230 --> 00:02:17,430
So we want to add to it.

33
00:02:17,460 --> 00:02:20,900
So we want to make sure that it has an at symbol next.

34
00:02:21,060 --> 00:02:22,770
So that's the next thing that we're looking for.

35
00:02:22,920 --> 00:02:28,110
And then for the domain name, it can also have a pattern that we're looking for.

36
00:02:28,110 --> 00:02:34,230
And the pattern is almost going to be the same thing that we just looked at, where we've got the letters,

37
00:02:34,230 --> 00:02:38,750
the numbers, the dot, the underscore, the dash.

38
00:02:38,760 --> 00:02:40,550
So all of those are valid.

39
00:02:40,950 --> 00:02:44,790
And we also need to check to see all of the characters after that.

40
00:02:45,060 --> 00:02:47,030
And we're looking for a dot.

41
00:02:47,220 --> 00:02:52,860
So any of those ones that have a dot and we know that every email address is going to have a domain

42
00:02:52,860 --> 00:02:54,930
name and all domain names have a dot in it.

43
00:02:55,080 --> 00:03:01,190
So I sense where we're going to be looking for that dot so we can take the same thing and then the parent

44
00:03:01,200 --> 00:03:03,150
domain and the parent domain.

45
00:03:03,150 --> 00:03:05,640
So we're not looking for any additional dots.

46
00:03:05,850 --> 00:03:10,980
We're not looking for any underscore or dashes within the main domain name.

47
00:03:10,990 --> 00:03:13,670
So we see that we're returning back the email address.

48
00:03:13,920 --> 00:03:19,890
So this is a good way to validate and simply validate your email addresses to make sure that you're

49
00:03:19,890 --> 00:03:25,560
getting a valid email address and a great place to build your regular expressions.

50
00:03:25,750 --> 00:03:31,020
So now that we able to select out the email address from all of the other text, that means that we

51
00:03:31,020 --> 00:03:32,940
can use it as an expression.

52
00:03:33,150 --> 00:03:36,300
So you can bring that expression into our project.

53
00:03:36,630 --> 00:03:42,090
And the way that we do that is with the slash and then the other, so that when we refresh, we're going

54
00:03:42,090 --> 00:03:48,190
to check to see all of the email addresses and what's being returned back is it's false.

55
00:03:48,390 --> 00:03:54,510
So if we take that email address that we just created here within the regular expression and if we post

56
00:03:54,510 --> 00:03:59,000
this in, if we do sign up, we see that we're returning back a value of true.

57
00:03:59,250 --> 00:04:06,180
So that means that this email address passed out and we can also return back an error if it doesn't

58
00:04:06,180 --> 00:04:07,280
pass the check.

59
00:04:07,470 --> 00:04:13,530
So if result is not true, if it's false, then what we want to do is we want to pass over an error

60
00:04:13,530 --> 00:04:17,790
message and say that the email field is not valid.

61
00:04:18,030 --> 00:04:23,940
So we're passing over to that same function where we've got add error and we can write invalid and you

62
00:04:23,940 --> 00:04:28,270
can build out any number of errors and checks as needed.

63
00:04:28,740 --> 00:04:30,960
There's other things, too, that I wanted to add in.

64
00:04:31,110 --> 00:04:37,590
So before we continue, let's add in a variable for error and we're set that to false.

65
00:04:38,130 --> 00:04:40,350
So that basically means that there's no errors.

66
00:04:40,500 --> 00:04:44,130
But if we do return back any errors, we set it to true.

67
00:04:44,250 --> 00:04:47,850
And that means that this is our way to kind of stop the submission.

68
00:04:48,060 --> 00:04:53,430
If there's no errors that are going to get registered within any of these conditions that we know that

69
00:04:53,430 --> 00:04:56,160
the email and the form should submit.

70
00:04:56,580 --> 00:05:01,260
So now we're checking to see email addresses and we can also do a similar thing for.

71
00:05:01,420 --> 00:05:08,170
The password, if we want letters, numbers and characters, so you had to do that in the upcoming lesson,

72
00:05:08,190 --> 00:05:13,630
so this is the more complex one building at the regular expression to check, to see if emails and if

73
00:05:13,630 --> 00:05:14,610
there's valid emails.

74
00:05:14,770 --> 00:05:16,780
So go ahead and add this one into your project.

75
00:05:16,930 --> 00:05:23,860
And coming up next, we'll do a check on the password feel to check to see its length as well as we're

76
00:05:23,860 --> 00:05:26,460
going to check to see if it's got the right characters.

77
00:05:26,830 --> 00:05:28,930
So go ahead and add that into your project.
