So we're almost done our server side form validation, and here's where we are right now, we can try
to submit this form and these three are currently required.
This one is not.
And this actually works.
I can actually try this make reservation and it will say no, got to be at least three characters so
I could make that three.
And but the problem is here under email, I can put just a letter and that accepts it.
It's fine.
And we want that to verify that it's actually an email.
So we can do that.
You can do it manually and it's rather lengthy and difficult.
But there's a simple way to do this.
And this is a package I mentioned a little while ago called Go Validator.
It's a very good package.
It's been around for a long time.
It's been well tested and I've been using it for, well, pretty much shortly after it came out.
So let's install that.
So the URL is right here.
Go to GitHub Dotcom as a K in the Chicago validator.
So go there and you go down to the install part and we're going to use this version.
We're not going to use this version because it's not really set up for packages correctly and it doesn't
matter for our purposes right now.
We'll just copy this, go back to our project, make sure a terminal window is open and paste that in,
make sure you're in the correct directory.
So I am right now on a Mac, at least I can type.
Would you make sure you're in the correct directory on Windows?
And you will notice that I moved my project out of visual studio code into goaland projects.
Just cleaner for me because that's where I put most of my go code.
So I'm going to paste in this, go get command.
It will go and get it.
And there it is.
Now we want to use it.
So what we need to do, first of all, is to set up a validator.
We want to set up a Veldheer that checks that something is an email.
So I will hide my terminal window.
I'm going to go to my forms page or forms go code and write at the very bottom.
I'll put in a new [REMOVED] func and again, it's for effort.
It takes the receiver for form.
So I'll use that and I'll just call.
This is email.
That's all I have to do.
And what I'm going to be checking again, as usual, is a field which will be passed as a string and
that's all I need to pass it.
And all I'm going to do is called go validator and go validator is really, really good at validation.
So if I don't want to check to make sure that this is an email, so I'll check to see if I get a response
of Fault's from calling go validator and it actually puts it in there for me in my autocomplete.
But I don't want abs and I just want to check his email and pass it.
Feel sorry, not pass at the field, pass it the form object, the pointer that we have, the form object,
get the function on that and, and the field is field so that will get whatever the user typed into
whatever field name we've passed here.
We call dars email in our forms that will go to the form post, look for the entry labeled email and
get the value.
And if, if that of course fails that check, what do I do?
Same thing I've been doing right along.
F dot errors dot add and add an error for this field and the error is invalid.
Email address.
All right, now let's give this a comment.
Keep things nice and neat checks for valid email address.
All right.
So I've added that as a new validator so I can go back to my handlers over here, find the post for
reservation right here and add another check form.
DOT is email and I'm checking the of the form field email, and that's all I have to do.
So let's run our application, go run command web, start up, go.
Let's go back to our page on our site and reload it to make sure that we actually can do this properly.
Let's make sure all the other validations work.
They do that one works.
Now let's put an AI in here, which is not a valid email address, invalid email address.
Let's put a at a invalid email address and now let's make a valid email address.
That one is valid there.
There's our VM email validation and that's all we really need to do for this.
So that was pretty straightforward.
In the next lecture.
What I want to do is when this form is filled out properly.
So I have enough valid information in here to get past the check.
I don't need phone right now.
It displays a blank screen.
I want I want to do in the next lecture is actually display the results of our reservation.
And as you probably guessed, we really don't have enough information on our form right now to make
a true reservation.
We have the first name.
We have the last name we have.
The email we had, the phone, we don't know what room they're making a reservation for and there's
other information we want as well, but we'll add that as time goes on.
Right now, we're just getting our validation working and we can create all the validators we think
we need.
So in the next election, we'll make sure that we do fill this out.
You don't get a blank screen.