Forms Validation Attributes: required, pattern, min, max
Foomamka (forms) ee HTML waa hab muhiim ah oo ay isticmaaleyaashu ku gudbiyaan macluumaadka websaydhka. Si loo hubiyo in xogta la gelinayo ay sax tahay oo aanay lahayn khaladaad, HTML waxay bixisaa sifooyin gaar ah oo lagu xaqiijinayo foomamka. Qaar ka mid ah sifooyinkaas waarequired
, pattern
, min
, iyo max
. Sifooyinkan waxay fududeeyaan xaqiijinta xogta qeybta frontend-ka, taasoo hoos u dhigaysa culeyska backend-ka waxayna hagaajinaysaa waayo-aragnimada isticmaaleha.![]() |
Forms Validation Attributes |
1. Sifada required
Sifada required
waxay hubisaa in goobta macluumaadka (input field) aanay banugayn oo ay tahay in la buuxiyo inta aan foomka la gudbin. Tani waxay tusaale u tahay goobta magaca isticmaalaha (username) ama iimaylka, kuwaas oo muhiim u ah inay jiraan.
Tusaale:
<label for="email">Iimaylka:</label> <input type="email" id="email" name="email" required>
Halkan, isticmaaluhu waa inuu buuxiyaa goobta iimaylka si uu u gudbi karo foomka.
2. naqshada labaad pattern
Sifada pattern
waxay u ogolaataa inaad sheegto qaab (regex) oo macluumaadka la geliyo uu raaco. Tani waxay ku habboon tahay goobaha sida lambarka taleefanka, erayga sirta ah (password), iwm.
![]() |
Forms Validation Attributes |
Tusaale:Copy
<label for="phone">Lambarka Taleefanka:</label> <input type="text" id="phone" name="phone" pattern="[0-9]{10}" title="Fadlan geli lambar 10 qodob ah">
Halkan, isticmaaluhu waa inuu geliyaa lambar 10 qodob ah oo kaliya.
3.min
iyo max
Sifooyinka min
iyo max
waxay xaddidooyin ku sameeyaan tirada ugu yar (minimum) iyo tirada ugu badan (maximum) ee la geli karo. Tani waxay ku habboon tahay goobaha sida da'da, tirada alaabta, iwm.
![]() |
Forms Validation Attributes |
Tusaale:
<label for="age">Da'da:</label> <input type="number" id="age" name="age" min="1" max="120">
Halkan, isticmaaluhu kama geli karo tirada ka yar 1 ama ka weyn 120.
4. Tusaale Dhamaystiran
Halkan waxaad arki kartaa sida sifooyinkan loo isticmaali karo si loo xaqiijiyo foomamka.
<form> <label for="username">Magaca Isticmaalaha:</label> <input type="text" id="username" name="username" required><br><br> <label for="password">Ergayga Sirta Ah:</label> <input type="password" id="password" name="password" pattern=".{8,}" title="Fadlan geli erayga sirta ah ugu yaraan 8 xaraf"><br><br> <label for="quantity">Tirada Alaabta:</label> <input type="number" id="quantity" name="quantity" min="1" max="10"><br><br> <input type="submit" value="Gudbi"> </form>
5. Faaiidayada Sifooyinka Xaqiijinta
Fududeynta Shaqada: Xaqiijinta macluumaadka waxaa la qaban karaa qaybta frontend, taas oo ka dhigaysa backend inuu shaqo yar qabto.
Tayada Macluumaadka: Waxay hubisaa in macluumaadka la geliyo uu yahay mid sax ah oo aan lahayn khaladaad.
Saadka Isticmaalaha: Isticmaaluhu wuxuu helayaa falcelin degdeg ah marka uu khalad sameeyo, taas oo ka dhigaysa foomka mid fudud oo sahlan in la isticmaalo.
6. Qoraal Dhamaystiran
Sifooyinka lagu xaqiijiyo foomamka HTML-ga, sida required
, pattern
, min
, iyo max
, waxay muhiim u yihiin siday u fududaan in la hubiyo tayada macluumaadka la geliyo. Iyaga oo isticmaalaya qaabab fudud, waxay ka caawiyaan in la yareeyo khaladaadka iyo in la hubiyo in foomka la buuxiyay si sax ah. Tani waxay kor u qaadaysaa waxtarka foomamka iyo saadka isticmaaluha.