All language subtitles for 004 Defining Rules_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

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.