Lekcje na YouTube >> "Kamil Audio Video Informatyk"
Strony 1
Zaloguj się lub zarejestruj by napisać odpowiedź
Nie jesteś zalogowany. Proszę się zalogować lub zarejestrować.
Lekcje na YouTube >> "Kamil Audio Video Informatyk"
Zespół Szkół i Placówek Oświatowych w Barlinku → 4Ti-Tworzenie stron i aplikacji internetowych → Walidacja formularzy
Strony 1
Zaloguj się lub zarejestruj by napisać odpowiedź
<script>
function funkcja()
{
var imie = document.getElementById('imie');
var nazwisko = document.getElementById('nazwisko');
var telefon = document.getElementById('telefon');
var email = document.getElementById('email');
var regulamin = document.getElementById('regulamin');
var wynik = document.getElementById('wynik');
//
const regEmail = /\S+@\S+\.\S+/; //wzór email
//
var B = [];
// imie
if (imie.value.length<=0) B.push("Wypełnij poprawnie pole z imieniem.");
// nazwisko
if (nazwisko.value.length<=0) B.push("Wypełnij poprawnie pole z nazwiskiem.");
// telefon
if (telefon.value.length!=9) B.push("Wypełnij poprawnie pole z telefonem.");
// email
if (!regEmail.test(email.value)) B.push("Wypełnij poprawnie pole email.");
// regulamin
if (!regulamin.checked) B.push("Zaakceptuj regulamin.");
if (B.length==0)
wynik.innerHTML = "Formularz prawidłowy.";
else
wynik.innerHTML = B;
}
</script>
<h1 style="margin: 100px;">
<form>
<span id="wynik" style="color: blue;">Wypełnij formularz</span>
<hr>
Imię:<br>
<input type="text" value="" id="imie"><br>
Nazwisko:<br>
<input type="text" value="" id="nazwisko"><br>
Telefon (np. 123456789):<br>
<input type="text" value="" id="telefon"><br>
E-mail:<br>
<input type="text" value="" id="email"><br>
<input type="checkbox" value="" id="regulamin"> Akceptuje regulamin<br>
<hr>
<input type="button" value="Sprawdź" onclick="funkcja()">
</form>
</h1>
Strony 1
Zaloguj się lub zarejestruj by napisać odpowiedź
Zespół Szkół i Placówek Oświatowych w Barlinku → 4Ti-Tworzenie stron i aplikacji internetowych → Walidacja formularzy
Forum oparte o PanBB, wspierane przez PunBB Info