Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this lecture, we're going to learn how to define rules.
A rule is a function that will take in the input value.
The value returned by the function will let the validation library know if the input is valid.
Let's take a closer look.
By default, the validate does not assume what requirements and input must meet.
To be valid.
We need to tell it exactly what rules we want to enforce.
Not only that, but we also need to tell it what rules will exist in our application.
Validate does not load rules into our application.
This keeps the build small and lean.
We need to manually import them if we want to use them.
Alternatively, we can define custom rules.
I find that the rules that come bundled with validate will cover most scenarios.
Let's import some rules.
In the resource section of this lecture, I provide a link to a list of available rules.
This page goes over how you can use the rules available in the V validate library.
We'll go over how to use them soon.
Scroll down to the section of available rules.
There are over 20 available rules we can test for things like a credit card number, numeric and URL
values.
The first rule will be using is called the required rule.
This rule will make sure the input has a value.
We want to make it a requirement for the input to be filled.
This is the rule we'll want to add.
The first thing we'll need to do is install the rules.
The official rules are installable via a separate package.
Let's switch over to the command line.
If you have the server running, turn it off.
After doing so, run the following command.
NPM install at V.
Validate slash rules.
The rules have been installed successfully.
Let's go back to our editor to start using them.
The next thing we'll be doing is register the rule.
Rules can be registered locally or globally, will be performing validation on multiple forms.
In our application, it would be better to register the rules globally so that they're readily available.
Switch over to your editor.
At the top of the validation file will import the required rule from the the validate rules package.
Rules are named spaced.
We must structure the object to grab a specific rule.
The next thing we'll do is update the import statement from the the validate package.
We'll want to import a function called define rule.
The defined rule function allows us to register a rule globally.
The rule we register will be available to every validation form we create in the install function we're
going to call the defined rule function.
The first argument is the name of the rule.
You can call this whatever you want.
You don't have to use the same names listed on the documentation.
The first rule will want to create is the required rule for consistency reasons we'll call it required.
The second argument is a function that will perform the validation.
We don't need to define a function because we are importing the required function from the rules package.
Every rule we're importing is already a function.
We can pass it in as the second arguments.
By using the defined rule function, we've successfully registered a new rule.
This rule will be available to every validation form.
Let's start applying rules in the next lecture.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.