MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / checkInputs

Function checkInputs

assets/js/Form-validation/script.js:13–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11});
12
13function checkInputs() {
14 // trim to remove the whitespaces
15 const usernameValue = username.value.trim();
16 const emailValue = email.value.trim();
17 const passwordValue = password.value.trim();
18 const password2Value = password2.value.trim();
19
20 if (usernameValue === '') {
21 setErrorFor(username, 'Username cannot be blank');
22 } else {
23 setSuccessFor(username);
24 }
25
26 if (emailValue === '') {
27 setErrorFor(email, 'Email cannot be blank');
28 } else if (!isEmail(emailValue)) {
29 setErrorFor(email, 'Not a valid email');
30 } else {
31 setSuccessFor(email);
32 }
33
34 if (passwordValue === '') {
35 setErrorFor(password, 'Password cannot be blank');
36 } else {
37 setSuccessFor(password);
38 }
39
40 if (password2Value === '') {
41 setErrorFor(password2, 'Password2 cannot be blank');
42 } else if (passwordValue !== password2Value) {
43 setErrorFor(password2, 'Passwords does not match');
44 } else {
45 setSuccessFor(password2);
46 }
47}
48
49function setErrorFor(input, message) {
50 const formControl = input.parentElement;

Callers 1

script.jsFile · 0.85

Calls 3

setErrorForFunction · 0.85
setSuccessForFunction · 0.85
isEmailFunction · 0.85

Tested by

no test coverage detected