Hi, Alex here from rebeloper.com and welcome back to this video and
welcome back to the series about regex and in this episode we are going to talk
about how to validate passwords. So without further ado let's get started.
Okay! If you already haven't done so go ahead and take a look at the previous
videos in this episode series because we have already built up our example
project and we already have validated age and email and today we are going to
validate password. But because this project is setup and I don't want to go
through it again go ahead and take a look at those videos
so we may better understand the logic and the structure of this project.
Now let's dive into checking or validating passwords. Now why don't do we need to
validate passwords. Well we want to validate them because we want our users
to have a strong passwords. Now strong passwords have letters, capitals and
characters and they must be at least six characters long.
So this is what we are going to implement and check for validity with regex.
In this episode of regex mania. So that is the name of our projects.
So let's jump right into it and to take a look at our extensions. Validity type.
We have two types of validity age and email. So let's add another one here. Case
password and let's just wait for it. As usual and as you could see in the
previous video we have started adding the next switch case here and I am just
going to copy and paste that in there. We're going to change the case to
password and of course the regex shouldn't be email but
it should be case password and I'm just going to leave it as an empty string for now.
So let's add that in here, okay. One last thing that we need to change and
I'm going to come back to the regex in just a moment before we dive into it
deeper is to change the validity type inside our root view controller to
password. Now let's get back to the good stuff. So here we have our regex. In the
age we have numbers, minimum number two maximum count of the string to email a
lot of stuff but here we have at and the dot and the minimum number of the
characters too and maximum sixty-four. Now as you might have guessed the
password is much more complicated. So again I will just copy and paste it from
our test example here and let me just copy again no peeking for the website
but if you did go ahead and do but we have some awesome exclamation in the
next video. So what do we have here? Well it's kind of a crazy gibberish talk here
but let me just try to comprehend it for you and make a distal.
So this symbol says that okay we are starting. Now with the question mark as
you might have guessed if it has okay if it doesn't have an okay. So we have all
of this and this is a wild card parameter what this basically does is
lets, it validate a password that has small letters, capital
letters and special characters and really recall what this does maybe, maybe
a space it doesn't have a space or something like that. I don't really
know but it does the job and it has to be
at least six characters and at most 25 characters. Now again if you want to
dive even deeper into regex go ahead and take a look at this link and let me
just jump right into it. This cheat sheet explains it all. Here we have our special
characters here, pattern modifiers and so on.
If you wanted to but this is a great way to set up our password validation.
Go ahead and simply just copy and paste it out just like I did. Now I believe we
are ready to test it out. Let's just double check yeah we did set this the
password and let's a build and run and see our password being validated
instantly, okay. Let's type in our password of course if we wanted to we
could set this to be a password text field and as bonus I will just show you
that in just a second. But for now let us just see the password what we are typing in.
So let's say we want to have password. Not a valid password. let's 123123.
Not a valid password. So let's add it here a valid
password already. So what I like to do is add all of the characters and this
really helps me out A s exclamation mark 2 3 and 4. So it has it all.
It has numbers, capital letters, small letters, special character and it's
really easy to remember and I usually use this in test mode when I want to let
a login to firebase, okay. And that is a valid password. Really nice if I just
type a backspace there still not a valid password and why because it needs
to have at least six characters. So let's jump back to with 4 and that is it
for this tutorial how awesome was it. Now again if you
don't know what I'm talking about here with this project go ahead and
the link in the description so you may get the starter project and of course
take a look at the previous videos how we have built all of this out because
it's of course it's not all about the regex here but to just simply copy and
paste it it's all about understanding the project that we are building.
Now I hope you enjoyed this video if you did go ahead and give it a thumbs up,
subscribe to the channel and hit that notification bell to get notified of
new videos and the next newest video in this tutorial series and of course the
last will be about validating websites and that will be a whole lot of fun.
So as usual I will see you in the next one.