WEBVTT 00:02.280 --> 00:07.740 So let's use the validation package we just created and we're going to do that in Handler's Dash API, 00:07.740 --> 00:11.000 in the function name to create customer and subscribe to plan. 00:11.700 --> 00:16.530 And as you can see right here on line one, thirty five of my code, the data we're getting from the 00:16.530 --> 00:20.700 front end is actually marshalled into straight payload. 00:21.120 --> 00:23.580 So we decode it into straight payload. 00:23.760 --> 00:26.880 And that type, as you can see over here, has a bunch of fields. 00:26.880 --> 00:29.240 And we're going to pay attention to this one first name. 00:30.150 --> 00:33.060 So the place to do the validation, of course, is right here. 00:33.060 --> 00:35.180 And we want to stop if the data is not valid. 00:35.190 --> 00:38.760 So let's just put a comment in here, validate data. 00:39.540 --> 00:42.330 And to do that, we simply create a validator. 00:42.420 --> 00:49.860 So I'll call that the and that's a sign the value of valid data for the new. 00:49.960 --> 00:51.620 I don't think it did the import for me. 00:51.630 --> 00:54.240 So let's go over here and import it. 00:54.570 --> 01:01.740 I'll just duplicate this line and add this valid data and I should take care of that. 01:02.260 --> 01:03.370 So we have a validated. 01:03.430 --> 01:04.740 Now let's do a check. 01:04.950 --> 01:05.900 And it's really simple. 01:05.910 --> 01:09.840 So I want to check to make sure that there's at least two characters in the first name. 01:09.840 --> 01:13.140 And that's totally arbitrary because I just want to show you how the validator works. 01:14.010 --> 01:19.440 So from the variable V, we'll call the builtin method check and the first argument is a boolean. 01:19.740 --> 01:23.790 And as you know, we can do something as simple as this. 01:24.210 --> 01:30.120 Lenn data first name is greater than zero. 01:30.480 --> 01:35.730 That will return true or greater than one, I guess, because you want to make it at least two characters 01:35.730 --> 01:37.770 long that will return. 01:37.770 --> 01:42.790 True if there's at least two characters in the first name and then return false otherwise. 01:43.200 --> 01:44.520 So that's the first argument. 01:44.970 --> 01:52.470 The key we want to check is called First Underscore Name, and that's what it's called in the JSON, 01:52.470 --> 01:53.010 of course. 01:53.370 --> 02:00.930 And we give it some error message must be Olinka Lowercase must be at least two characters 02:04.530 --> 02:05.850 and get rid of the space. 02:07.350 --> 02:08.420 And that's all I have to do. 02:08.520 --> 02:11.040 So I'll close this one now to give us a little more room. 02:11.700 --> 02:14.100 So that actually performs the check. 02:14.640 --> 02:18.000 And now below it, you can put whatever checks you want in there. 02:18.000 --> 02:20.780 Of course, now we just check to see if there's any errors. 02:20.790 --> 02:34.950 So if not Vidor's valid, then I say app failed validation and give it an hour and vidaurre errors and 02:34.950 --> 02:35.270 return. 02:35.400 --> 02:36.420 So I don't want to go any further. 02:37.320 --> 02:39.090 And literally that's all I have to do. 02:39.300 --> 02:42.870 Now, obviously, you can make really simple checks here. 02:43.350 --> 02:45.720 You could have one for last name if you wanted to. 02:45.730 --> 02:48.450 So I just duplicate it like this and make it last name. 02:49.620 --> 02:54.870 And of course, these values here have to correspond to whatever the entry is in the JSON because we 02:54.870 --> 02:56.370 want to send that information back. 02:57.150 --> 03:02.280 And all I can say is if last name data dot last name 03:06.000 --> 03:13.230 equals an empty string and give that error and you can't get much simpler than that, it's pretty straightforward. 03:13.320 --> 03:14.820 Now, I'm not going to do this second check. 03:14.910 --> 03:16.090 I'm just going to do the first one. 03:17.160 --> 03:20.430 So the next step is to go update our JavaScript on the front end. 03:21.000 --> 03:26.580 And after we call fetch, we check to see if there's an error and do something with that information 03:26.580 --> 03:28.820 and we'll take care of that in the next lecture.