1
00:00:00,360 --> 00:00:01,810
Hi there and welcome back.

2
00:00:01,830 --> 00:00:08,730
This lesson we're going to be checking to see if our password passes our check as well so we can get

3
00:00:08,730 --> 00:00:12,840
rid of these console messages so they're not interfering with our program.

4
00:00:12,850 --> 00:00:13,980
We don't need them anymore.

5
00:00:14,160 --> 00:00:20,640
Get rid of all the console messages that we've been using and we're going to do a check to see if the

6
00:00:20,640 --> 00:00:22,470
temp name is password.

7
00:00:22,740 --> 00:00:27,770
So if it's a password, then there's a few conditions that we need to pass through there.

8
00:00:27,780 --> 00:00:30,740
So passwords and our expressions.

9
00:00:30,740 --> 00:00:35,340
So create a brand new expression that we're going to be looking for and for passwords.

10
00:00:35,580 --> 00:00:41,620
We want to check to see if it's digits, lowercase, uppercase, all OK.

11
00:00:42,180 --> 00:00:49,710
So making sure that we're checking to see if this is matching and if it is, then this is going to be

12
00:00:49,710 --> 00:00:54,270
a valid password that we can use so we can also do a test.

13
00:00:54,270 --> 00:00:59,460
So just as we did in the previous lesson, we've got tests and there's some more information on tests

14
00:00:59,460 --> 00:01:01,080
on the material developer network.

15
00:01:01,290 --> 00:01:06,360
So if you never use tests before with regular expressions, they're ideal, where you can execute a

16
00:01:06,360 --> 00:01:11,880
search for a match between a regular expression and a specified string returns, true or false?

17
00:01:12,060 --> 00:01:16,650
So you've got the regular expressions are here and the string is this one.

18
00:01:16,800 --> 00:01:22,380
So it's testing regular expression, one triangle expression, two on the string and so on.

19
00:01:22,620 --> 00:01:26,940
So we've got the expected output here so we can use test whenever we want to know.

20
00:01:26,940 --> 00:01:31,230
If a pattern is found within a string, it returns a boolean value.

21
00:01:31,260 --> 00:01:33,960
There's some more examples as well down below.

22
00:01:34,080 --> 00:01:38,460
So let's have the Metsola developer network, so let's go ahead and bring that into our project.

23
00:01:38,610 --> 00:01:42,330
So we're taking checking to see if this content is true.

24
00:01:42,540 --> 00:01:45,300
We've got our test here that we're doing so.

25
00:01:45,300 --> 00:01:51,720
We're using our expression with a test and testing again, that value that's contained within that element.

26
00:01:51,720 --> 00:01:56,150
If the result comes back negative, then we can pass on a message.

27
00:01:56,580 --> 00:01:59,760
So only numbers and and letters.

28
00:01:59,880 --> 00:02:03,090
And there's one other thing that we do need within the regular expression.

29
00:02:03,090 --> 00:02:09,980
And we need to sign in order to check to see if these characters match and up to the dollar sign.

30
00:02:10,020 --> 00:02:12,410
So let's try that in our expression.

31
00:02:12,840 --> 00:02:14,580
So we've got some letters here.

32
00:02:14,580 --> 00:02:16,320
So that's OK.

33
00:02:16,500 --> 00:02:20,760
If we've got special characters, only numbers and letters are valid.

34
00:02:20,760 --> 00:02:24,640
So let's change these into numbers and we can see that that's all OK.

35
00:02:24,900 --> 00:02:29,640
So there's one other thing that we do still need to do and that's remove out all of those error messages,

36
00:02:29,880 --> 00:02:34,740
because when we try to submit it again, all of the error messages are still there.

37
00:02:34,950 --> 00:02:40,980
So we can do that by looping through all of the errors that we have on the page and looping through

38
00:02:40,980 --> 00:02:43,350
all of those elements with a class of error.

39
00:02:43,680 --> 00:02:48,750
And through for each one of those, we can output them as a variable called item.

40
00:02:48,990 --> 00:02:56,910
And then as we loop through the item, we can take the class list and add height to it.

41
00:02:57,270 --> 00:03:03,290
So simply adding hyd to all of the elements and what that will do is hide it.

42
00:03:03,300 --> 00:03:08,310
So when we do turn valid and if we're submitting again, if we've got some more errors, you're going

43
00:03:08,310 --> 00:03:09,870
to see that they're disappearing.

44
00:03:10,200 --> 00:03:16,620
And if we update this and save it and then if we make a mistake again, you're going to see it shows

45
00:03:16,620 --> 00:03:16,770
up.

46
00:03:16,770 --> 00:03:18,870
The error message shows up once again.

47
00:03:18,900 --> 00:03:20,420
So now that's a required field.

48
00:03:20,580 --> 00:03:25,650
So everything is good and we should actually be able to submit the form at this point.

49
00:03:26,010 --> 00:03:33,300
Also, one other thing, if we want to check to make sure the length of our password is less than eight

50
00:03:33,300 --> 00:03:35,470
characters are longer than eight characters.

51
00:03:35,610 --> 00:03:37,710
So there's another condition that we can pass in.

52
00:03:37,710 --> 00:03:40,830
So we've got the first condition and this condition.

53
00:03:40,840 --> 00:03:48,030
So it's still checking on the password field and we can check to see if element of value is greater

54
00:03:48,030 --> 00:03:51,450
than three and element.

55
00:03:52,790 --> 00:03:56,070
Value and that's actually value is less than eight.

56
00:03:56,090 --> 00:04:02,540
So we want a password with the length of between three and eight characters and they have to be digits

57
00:04:02,540 --> 00:04:04,400
or no no special characters.

58
00:04:04,700 --> 00:04:07,960
So if it's good, then we're good to pass through.

59
00:04:08,090 --> 00:04:14,520
But if it's not if it's not meeting these parameters, then we want to part throw an error there.

60
00:04:15,020 --> 00:04:18,060
So let's do that and we'll negotiate that with an error.

61
00:04:18,350 --> 00:04:24,680
So if this is coming back as false, that we need to add in our error message and we can write needs

62
00:04:25,310 --> 00:04:29,830
to be between three and eight characters.

63
00:04:30,500 --> 00:04:31,510
So let's try that.

64
00:04:31,670 --> 00:04:36,980
So this time in the password, we can see that we've got that needs to between three and eight.

65
00:04:37,220 --> 00:04:38,360
So everything is good.

66
00:04:38,390 --> 00:04:42,280
When we go over eight, we've got that message again between three and eight.

67
00:04:42,800 --> 00:04:48,350
So once we've got that everything in place, we can actually submit the form and I'll show you how to

68
00:04:48,350 --> 00:04:49,400
do that coming up.

69
00:04:49,430 --> 00:04:54,470
So that means that none of the errors were true and we are OK to submit the form.

70
00:04:54,800 --> 00:04:58,830
And if the errors are true, then we're not going to be submitting the form.

71
00:04:59,300 --> 00:05:00,990
So that's still to come in the next lesson.

72
00:05:01,010 --> 00:05:03,800
So go ahead and add in some additional conditions.

73
00:05:03,800 --> 00:05:07,040
You can add it on password and you can also add and so on username if you want.
