Welcome to Day 43 of our Next.js 15 + MySQL Job Portal Application. In this video, we implement enterprise-level form validation for the Employer Profile Settings Form using Zod and React Hook Form.
You will learn how professional companies validate user profile forms using a strongly-typed schema, safe parsing, and clean error handling.
What we cover:
Creating a Zod schema for employer profile data
Understanding how Zod validation errors look internally
Generating TypeScript types from the schema
Integrating Zod with React Hook Form using zodResolver
Displaying real-time error messages in the UI
Styling validation errors to match professional design systems
Expanding validation to multiple fields step-by-step
A small task for viewers to practice with more fields
This video delivers industry-grade best practices used in real corporate projects. ---------------------------------------------------------------------------------- 📂 Source Code 👉 GitHub Repo: https://github.com/thapatechnical/job-portal-nextjs
⌛TIMELINE⏳ 0:00 — Employer Profile Form Validation with Zod 0:30 — Understanding Zod Error Structure (How Errors Look) 0:50 — Support the Channel 1:15 — Why You Must Watch the Zod Video First (Recommended) 1:50 — Folder Structure Overview for Validation Setup 2:40 — Creating Employer Profile Zod Schema 12:10 — Defining TypeScript Types from Our Schema 13:35 — Adding the Type to useForm Hook 14:50 — Using Schema in useForm via zodResolver 17:00 — Displaying Error Messages in Input Fields 18:30 — Styling the Validation Errors Professionally 19:30 — Adding More Validation Rules to Additional Inputs 20:05 — Task for Viewers (Practice Assignment)
Hello, what's up guys? Welcome to the next session of MySQL Present Job Portal Application.
Today is our day number 43 and today we are going to see employee profile, basically setting profile
job validation. This means that we have seen very well how we can create this form.
We have seen how I can update the user who is filling in this form in my database.
And we understood the logic behind it in depth very well. But today is a very important topic
and that is to use the validation using JWT.
Here you can clearly see how the border of the field where the error is is red.
And right below that field, you will see the error message that we are passing through JWT.
So this is perfect where you are very easily telling your users that
you have to fill this type of data on this field, not this type of data.
So without any delay, let's start the video. But before that, if you have not checked out the previous video,
then definitely do it. The source code is completely free. And guys, please like the video and share it with your friends.
And if you want to support me, if you like my hard work, then guys, I don't need anything.
Just subscribe to my channel. I will be very happy.
So guys, now let's go to our VS Code Editor without any delay.
And here you can see, this is our code through which you can see all this here.
I need validation here. And we have already uploaded a lot of videos on JWT.
And even I think you can see it here too. Even React Hook form plus JWT.
Even here also we have a JWT. And there is also a registration form.
And we have a login form. Here too, we have already implemented JWT in our React Hook form.
So I hope that you have seen this video very well.
So at least now you have an idea how we can use it here.
And for the same reason that you don't have any problem.
That's why if you see, the folder structure is very important.
First of all, this is what I would like to say.
Here you can see, we have a features over here.
And in the features, we have what? We have employers.
Okay?
In the features, we have employers.
And I have made a file directly below the employers.
Basically, in the employers folder, I have made a direct child.
Who?
So this should be your file.
Basically, this should be the structure of your file.
Where do you want to use your schema for your employer's profile setting form?
Where do you want to use it?
So let me go to employers.schema.ts.
Here you can see very clearly that I have already created our schema using Jodo.
Already in this playlist, in this series, I have told you every single thing in-depth here.
Which is new.
No doubt, I will explain to you A to Z, line by line.
But I have already written it so that it becomes easy for you.
First of all, if you want to validate through Jodo, we need to import Jodo.
Right?
Basically, you have to install it first.
And then we need to import Jodo from Jodo.
Simple.
Like this.
Then, let it be for now.
I will come here directly first.
Now, what we do here is, we create a schema.
For whom are we doing it now?
We are doing it for employers.
And what is there in employers?
It is the profile form of employers.
So, employer profile schema.
I have given the name.
It is the name of the constant variable.
You can give any name.
But it is better to give the one that matches.
Then what we have?
We have a Jot.
And I am calling a method there.
Object.
Basically, you can call it a function.
I am calling this object function.
And when we call a function, how do we do it?
Parenthesis.
And I am passing an argument in it.
And that's your object.
So, that's why syntax is like this.
I will tell you again what I want to say.
Like, I have written here z.obj.
It is a function.
We call the function like this.
Now, I have to add some argument in it.
So, how will I do it?
I have passed the object.
Like, I have to call some function.
In which I am passing two arguments.
5 and 10.
So, what am I doing to this function?
I am calling it.
And what am I doing here?
I am passing an argument.
So, it is the same here.
This is your Jot.
This is your function.
And this is the function you are calling.
And I am passing an argument in it.
This is basically an argument.
And that's my object.
I am passing it.
So, that's why syntax is like this.
But it is simple.
You have to call the function.
And then object.
Okay.
So, what am I defining in it?
I am defining the structure of my employer's form here.
Its schema.
Like, I want to have a field named name in it.
Which should be a string.
Z.string.
Which I am trimming.
Means, from left and right side.
If someone has left a lot of empty space.
We will trim it.
Minimum should be 2 characters.
Maximum should be 255.
In case if it is less than 2.
Then we will throw this error.
And in case it is more than 255.
We will throw this error.
Like this.
Then we have a description.
I hope now you know very well.
See, this is the name.
And this is your description.
So, now we are in the description.
So, there is a string in the description.
There should be a trim.
Minimum this much.
Maximum this much.
Organization type.
And then the size of our team.
If you remember.
Both are like.
See.
This is a select field.
And even I made a separate video for this.
If you remember.
For this, I made a separate video.
Saying this.
That why in setCN.
Select is basically perfectly.
I mean.
Select works in setCN.
But when you are using react hook form.
With setCN.
So, there the select field.
Your basically select component.
Of setCN.
React hook form does not work that way.
So, to make it work.
In select.
Whoever is selecting.
To get its value.
We saw in react hook form.
We have something called controller.
So, through the controller.
We got the value.
Right.
And there.
I showed you one thing.
That now I.
I mean.
What are we using here?
We are using type script.
Okay.
So, when you are using type script.
So, we have to define type also.
So, here if you see.
It's like z.enum.
So, enum is basically enumeration.
In which we know that.
Now.
When you pass the enum type.
It means.
You have a set of.
Values.
From that only.
You have to select one.
Neither less nor more than that.
So, we have made the same enum.
Organization type.
And see this.
I also told you.
If you remember.
This is our form.
Here see this.
In organization type.
I wrote organization type.
Rather than.
Writing like simple.
Any type of form.
You know.
Like data type.
Like string number.
Or boolean whatever.
I wrote organization type.
Why I wrote?
Because here.
I created organization type.
Even I wrote here.
As const.
And we write as const.
At the end.
Like after array.
As const.
So that.
It's not considered a plain string.
Now.
I wrote as const here.
Consider it read only tuple.
Read only tuple.
What will happen with this?
Now in the next day.
In this array.
On my index number 1.
What value is this?
Even what is its type?
Till that.
We can find out.
Through this.
Okay.
So this means that.
We have already seen this.
It's just here.
I kept it in simple term.
Now here.
I have added a little more value.
Rest.
Same as const.
And then.
We also got its type.
Type of organization.
Type options.
Organization type option.
Type of this way.
And same goes with.
Our team size.
Like.
Team size.
We also kept it like this.
And this is its part.
And here.
In this way.
Our.
Employer form field.
Basically.
The type of the form.
We defined it.
And here.
I added it.
So that.
Now.
We are taking it to the next level.
And.
Through jot.
We have done it here.
So this is my team size.
And as const.
I have kept it.
So.
The same organization type.
I have kept it above.
You can see.
First.
This is my nm.
In this.
My first argument.
Organization type.
Obviously.
And then comma.
And then we have this error.
Same goes with.
Our team size.
Please select a valid team size.
Year of establishment.
I'm.
Naked.
Problem.
Faced.
If you remember.
I got up.
To say.
Yadav.
So.
Year.
Of establishment.
You have a.
Simple.
String.
Right.
But.
When he.
Again.
I could.
Become.
Here.
We have a.
Year.
Of establishment.
Yeah.
Maybe.
Normal.
But.
Each.
Jk.
Pay.
They go.
Mara.
Hey.
Take a job.
Manipulate.
A key.
Mara.
Filka.
Data.
Co-op.
Kya.
Kareen.
Database.
Me.
Hum.
Update.
Kareen.
Yeah.
To.
Wapik.
Hum.
A problem.
Autarchy.
Year.
Of establishment.
Joe.
May.
Value.
Insert.
Karam.
Weak.
String.
But.
Hum.
Niska.
Type.
To.
A.
Number.
Define.
Karaka.
Then.
How.
To.
Hum.
Nika.
Ki.
Bhai.
Mara.
Of.
Establishment.
Koi.
Value.
Agar.
Hum.
A.
Milti.
Hai.
Then.
Usko.
May.
Pass.
End.
Kara.
To.
Basically.
Integer.
May.
Convert.
Karke.
Then.
May.
Usko.
Insert.
Kara.
Else.
Keep it.
Null.
Ye.
Hum.
Ne.
Lika.
But.
Wahi.
Same.
Cheez.
Yaha.
Pe.
Trim.
Kar.
Diya.
Hai.
Ab.
Yaha.
Pe.
Rejects.
Use.
Ki.
I.
Ki.
Bhai.
It.
Will.
Only.
Accept.
Four.
Digit.
Number.
To.
Ye.
Rejects.
Ka.
Code.
Is.
Sabab.
Sip.
Chaar.
Hi.
Digit.
Ka.
Basically.
Is.
Ki.
Baat.
Ho.
Re.
By.
The.
Way.
Ek.
Second.
Yaha.
Pe.
Jaisi.
Year.
Of.
Kuch.
Kisi.
Leh.
Eh.
Dekho.
Chaar.
Zyada.
To.
Ab.
Mein.
Lik.
Bhi.
Ni.
Sakta.
This.
Is.
The.
Beauty.
But.
Koi.
Agar.
Three.
Zero.
Three.
Two.
Lik.
De.
Matlab.
Abhi.
Kya.
Chal.
Rah.
2025.
Apne.
Lik.
Diya.
Guys.
Three.
Thousand.
Thirty.
Two.
Ek.
Baat.
Batao.
Ke.
Hum.
Like.
Kya.
Bhi.
2025.
And.
Ap.
Likh.
Rah.
Yeh.
Ha.
Pe.
Three.
Zero.
Three.
Two.
Obviously.
Bhai.
Future.
Baat.
Ho.
Rhi.
Future.
Mein.
Koi.
Apse.
Agar.
Yeh.
Bhole.
Ki.
Ap.
Kab.
Paid.
Ho.
Tha.
Ab yeh.
Boldo.
Ki.
Mein.
Dwo.
Azhar.
Ah.
Atheis.
Mein.
Paid.
Ah.
Callback.
Function.
Chala.
Yeh.
And.
This is.
First.
Argument.
Jisko.
Mein.
Get.
Come.
And.
That.
Is.
The.
Year.
To.
Is.
Year.
Mera.
Matlab.
Yeh.
Hai.
Ki.
Mujhe.
Us.
Field.
Pe.
User.
Neh.
Jo.
Bhi.
Saal.
Likh.
Haoga.
Jaise.
Do.
Azhar.
Ba.
Do.
Azhar.
Atheis.
Likh.
Two.
Zero.
Two.
Eight.
Mujhe.
Value.
Mili.
To.
Mein.
Kya.
Karo.
Usko.
Dekho.
Again.
Parcent.
Of.
I.
Hope.
Aap.
Remember.
Karo.
Ki.
Kalki.
Video.
Mere bhi.
Mere.
Parcent.
Likhai.
Tha.
Kyu.
Likhna.
Bada.
Aapko.
Pata.
Humne.
Number.
Mein.
Convert.
Kara.
And.
Mene.
Aaj.
Ka.
Jo.
Current.
Basically.
To.
User.
Kya.
Likha.
Tha.
And.
Abhi.
Filal.
Hamara.
Current.
Year.
Kya.
Mujhe.
Mil.
Gya.
Ek.
Simple.
Sa.
Condition.
Mene.
Yaha.
Pe.
Laga.
Diya.
Ki.
Hum.
Na.
Kya.
Karne.
Wale.
Hai.
Yaha.
Pe.
Dekh.
Lijiye.
Mein.
Chaunga.
Ki.
Athara.
So.
Se.
Lekhe.
Haina.
Athara.
So.
Se.
Wo.
Wali.
Main.
Chahta.
Hoon.
User.
Yaha.
Pe.
Fil.
Kare.
Let.
It.
Be.
Like.
18.
Oh.
One.
Let.
It.
Be.
Like.
19.
Oh.
One.
Let.
It.
Be.
Like.
2001.
Or.
2021.
Lekin.
2025.
Se.
Zyada.
Ni.
Hona.
Chiye.
And.
Do.
Ye.
Jo.
2000.
I.
Mean.
Athara.
So.
Se.
Kam.
Return.
Number.
Athara.
Bada.
Ona.
Chiye.
Or.
Current.
Year.
Se.
Chota.
Ona.
Chiye.
Agar.
In case.
Fail.
Ho.
Gya.
To.
Ye.
Hum.
Error.
Throw.
Kara.
Denge.
Then.
Website.
URL.
Bauti.
Zyada.
Simple.
Is.
Ko.
Hum.
Ne.
Optional.
Rakha.
Hua.
Hai.
And.
Jot.
Validation.
Main.
Agar.
Ap.
Optional.
Ko.
Optional.
Manta.
Kus.
Hum.
Error.
Throw.
Karta.
That.
Is.
The.
Reason.
Why.
Hum.
Ne.
Yaha.
Pe.
Ye.
A.
Dot.
Or.
Me.
Z.
Dot.
Literal.
Dala.
Is.
Ka.
Manlab.
Ye.
Hai.
Ki.
Ab.
Me.
Mere.
Jot.
Ko.
Ye.
Kya.
Rahon.
Suno.
Agar.
Kisi.
Ne.
Empty.
Chod.
Bhi.
And.
Our.
Location.
String.
Cream.
Main.
Max.
Optional.
And.
Again.
Agar.
Koi.
Empty.
Chodta.
Is.
Filko.
Toh.
Ap.
Usko.
Valid.
Samjho.
Ki.
Ha.
Bhai.
Saiye.
Because.
It's.
An.
Optional.
And.
Filal.
Avatar.
URL.
Ko.
Mene.
Hide.
Kar.
Rakha.
Hai.
I mean.
Comment.
Kar.
Rakha.
Kyuki.
Abhi.
And.
The.
Rest.
Abh.
Dekh.
Saktori.
Gya.
Pay.
Manne.
Kya.
Bolata.
Bhai.
Apne.
Chalo.
Banaliya.
Eskima.
Lekin.
Jab.
Ab.
Form.
Fill.
Karo.
Jab.
Ab.
Parameter.
Pass.
Karte.
Ho.
Ya.
Jab.
Ab.
Use.
Form.
Hook.
Use.
Kare.
Toh.
Waape.
Hame.
Johe.
Hamare.
Is.
Fill.
I mean.
Hamare.
Is.
Form.
Mein.
Type.
Employee.
Profile.
Eskima.
Pay.
Employee.
Profile.
Eskima.
Kya.
Obviously.
Mera.
Yeh.
Jiske.
Inde.
Mene.
Pura.
Object.
Bata.
Raka.
Kya.
Hona.
Chiye.
Sab kuch hai.
Toh.
Mujhe.
Uska.
Type.
Chaiye.
No.
Doubt.
Easy.
And.
Generic.
Toh.
Guys.
Z.
Infer.
Matlab.
Automatically.
Dekh.
No.
Doubt.
Toh.
Automatically.
Suggest.
Dekh.
Yeh.
Likhna.
Joh.
Yeh.
Joh.
Hai.
Maine.
Aapko.
Dikhaye.
Yaha.
Pe.
Yeh.
Joh.
Hai.
Wo.
Automatically.
Ab.
Yeh.
Aapka.
Likh.
Ke.
Hame.
Dera.
And.
Type.
Of.
Employee.
Profile.
Eskima.
Hame.
Pata.
Chal.
Jaega.
Aapko.
Eskima.
Karo.
Uska.
Aapko.
Type.
Chahiye.
Toh.
Kaise.
Ab.
Aap.
Pata.
Laga.
Sakte.
Type.
Of.
Dat.
Eskima.
Ka.
Naam.
Aapke.
Guys.
Angle.
Brackets.
Ke.
And.
Then.
We need.
To.
Write.
Z.
Dot.
Info.
Thek.
Toh.
Isse.
Ab.
Aapko.
Type.
Pata.
Chal.
Gaya.
Hai.
Ab.
Aap.
Comment.
Diji.
Because.
Iski.
Mujhe.
Need.
Nahi.
Hai.
And.
Yah.
Pe.
Dekhi.
Hum.
Dekh sakte.
Ki.
Yah.
Pe.
Mujhe.
Uski.
Need.
Thi.
Hamare.
Type.
Ki.
Toh.
Mera.
Jo.
Type.
Hai.
Wo.
Kya.
Hai.
It's.
Employer.
Profile.
And.
Then.
Data.
Employer.
Profile.
Data.
Yehi.
Toh.
Hai.
Aur.
And.
This.
It.
Thik.
Mera.
Kam.
Gaya.
Yeh.
Dekho.
Mujhe.
Yah.
Pe.
Already.
Aap.
Error.
Aaj.
Chuka.
Warning.
Mujhe.
Aaj.
Chuka.
Hai.
And.
Batara.
Ki.
Jo.
Data.
Wala.
Field.
Hai.
Kya.
Pata.
Barabar.
Aapne.
Nahi.
Likha.
Ho.
Hai.
Nahi.
Yeh.
Jo.
Data.
Kaha.
Pass.
Kar.
This.
Is.
It.
Yeh.
Mere.
Lik.
Dhi.
Is.
Tari.
Ke.
Se.
Toh.
Aap.
Mujhe.
Koi.
Problem.
Nahi.
Yeh.
Mera.
I mean.
Mera.
Jo.
Type.
Tha.
Ho.
Mere.
Already.
Yaha.
Chuka.
On.
Define.
Toh.
Mere.
Yaha.
Pe.
Chalta.
Ab.
Mujhe.
Yaha.
Pe.
Sab.
Kuch.
Set.
Hai.
Bas.
Ab.
Ek.
Cheez.
And.
Yeh.
Part.
Jo.
Aap.
Is.
Koo.
Bhi.
Comment.
Kar.
Diji.
Is.
Ki.
Bhi.
Humme.
Neet.
Nahi.
Hai.
Aage.
Ja.
Ke.
Mein.
Delete.
Kar.
Doonga.
Is.
Sab.
Kuch.
Toh.
Now.
Guys.
Sab.
Humare liye.
Important.
Hi.
Ki.
Jo.
Is.
Schema.
Humne.
Itni.
Mainaj.
Se.
Banaya.
Tha.
Is.
Save.
Pass.
Ke.
Kuch.
Aapko.
Ek.
Method.
Yaad.
Aar.
Aaga.
But.
Hiya.
Pe.
Aasa.
Kuch.
Nahi.
Yeh.
Hiya.
Pe.
Simple.
Aapka.
Use.
Form.
Hook.
Ke.
Andar.
Aapko.
Ek.
Configuration.
Object.
Basically.
Ek.
Object.
Pass.
Karna.
Is.
Object.
Ke.
Andar.
Aapko.
Multiple.
Properties.
Milta.
Jo.
Yeh.
Batata.
Ki.
Ab.
Jo.
I mean.
Employee.
Profile.
Is.
Kima.
Hota.
Yeh.
Hai.
Ki.
Ab.
Aap yeh.
Form.
Ko.
Kya.
Karoge.
Fill.
Karoge.
Filal.
Chalo.
Dikhne.
Rahe.
Mai.
Batata.
Hon.
Kya.
Problem.
Yeh.
But.
Jo.
Bhi.
Ho.
Form.
Ko.
Jab.
Aap.
Fill.
Karoge.
Hain.
Aai.
Yeh.
Aapka.
Form.
Hai.
Yeh.
And.
If.
There.
Is.
An.
Error.
Hoga.
Yeh.
Ki.
Yaha.
Pe.
Humare.
Paas.
Ek.
Ko.
Property.
Hai.
Form.
State.
Karke.
Ab.
Iske.
Andar.
Bhi.
Humare.
Paas.
Multiple.
Property.
Jisko.
Mai.
Directly.
Ab.
Destructure.
Karon.
Tik.
Errors.
Karke.
To.
Aayog.
Guys.
Aap.
Samajhge.
React.
Hook.
Form.
Jab.
Bhi.
Aap.
Arre.
Yeh.
Alag.
Hai.
Kya.
Karega.
Resolver.
Us.
Ab.
Field.
Ka.
Jo.
Message.
Jo.
Ko.
Extract.
Karega.
And.
Humare.
Form.
State.
Mai.
Yeh.
Jo.
Errors.
Karke.
Jo.
Object.
Hai.
Iske.
Andar.
Us.
Message.
Ko.
Put.
Kardega.
Rakh.
Dega.
To.
Matlab.
Yeh.
Hoga.
Ki.
Is.
Errors.
Organization.
Type.
Unko.
Nahi.
Milga.
Obviously.
Milega.
Bhi.
Nahi.
To.
Wo.
Mujhe.
Kaise.
Milega.
Mujhe.
Wo.
Organization.
Type.
Or.
Team.
Size.
Yeh.
Ha.
Se.
Milega.
Kyuki.
Yeh.
To.
Ab.
Mera.
Kidar.
Hai.
Yeh.
To.
Idar.
Hai.
Na.
Yeh.
Dekhna.
Array.
To.
Ab.
Mera.
Yeh.
Hai.
Organization.
Type.
Option.
Teri.
Se.
Bana.
Raka.
Te.
Is.
Le.
Us.
Ko.
Mila.
But.
Abhi.
To.
Wo.
Nahi.
Hai.
So.
That's.
The.
Reason.
Why.
Yeh.
Ab.
Mera.
Organization.
Type.
Jo.
Hai.
Is.
Ko.
Get.
Karunga.
Yeh.
Mera.
Theek.
Oge.
Same.
Goes.
With.
Our.
Team.
Size.
Also.
So.
We.
Have.
A.
Property.
Border.
Hyphen.
Destructive.
As it is.
I guess.
It's a.
Text.
Small.
And.
Text.
Hyphen.
Destructive.
And.
Yeh.
Name.
Company.
Name.
Be.
At.
Least.
Two.
Character.
Longs.
And.
Yeh.
Hain.
Hai.
Kitna.
Jada.
Awesome.
Matlab.
Ab.
So.
Cho.
Pehle.
Ki.
Jamane.
Mein.
Kya.
Kuch.
Nih.
Karna.
Pardata.
But.
Now.
We.
Have.
A.
Jod.
Now.
We.
Have.
A.
React.
Hook.
Form.
Mara.
Apna.
Khud.
Ka.
Form.
And.
Sub.
Mara.
Kaam.
Hoga.
Yeh.
Same.
Up.
Code.
Kuch.
Paste.
Copy.
Paste.
Copy.
Paste.
Karna.
Ab.
Yeh.
Ape.
Ake.
Ab.
Isko.
Description.
Kardo.
Ab.
To.
We.
Lend.
The.
Processor.
Kuch.
Nee.
Hai.
Description.
Kardo.
Okay.
Ab.
In case.
Ape.
Apne.
Yeh.
Ape.
Sab.
Yeh dekho.
Yeh.
I hope you liked the video, let me know in the comment section how did you like the video.
It takes a lot of hard work to make such a video.
Because you think you will not be told anything in the normal class institute.
Which I am telling you here for free.
So you can at least respect me.
If you think that the person is doing so much, I don't need anything.
Just subscribe to my channel, recommend it to your friends and share it.
And I don't want anything else.
I have kept the source code completely free.
If you haven't subscribed yet, please do it.
See you in the next video.
Till then guys, thank you so much.
Take care.