Form validation Flashcards

1
Q

Sometimes we have fields in our <form>s which are not optional, i.e. there must be information provided before we can submit it. how would you enforce this rule?

A

You can add the required attribute to an <input></input> element.
<input></input>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you assign a minimum and maximum value for a number field?

A

To set a minimum acceptable value, we use the min attribute and assign a value.
On the flip side, to set a maximum acceptable value, we assign the max attribute a value.
min=“5” max =“10”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you set the minimum and maximum amount of characters for text fields?

A

To set a minimum number of characters for a text field, we add the minlength attribute and a value to set a minimum value.
Similarly, to set the maximum number of characters for a text field, we use the maxlength attribute and set a maximum value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For cases when we want user input to follow specific guidelines, what attribute would we use?

A

Pattern attribute
Let’s say we wanted to check for a valid credit card number (a 14 to 16 digit number).
We could use the regex: [0-9]{14,16} which checks that the user provided only numbers and that they entered at least 14 digits and at most 16 digits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When does client-side validation occur?

A

Client-side validations happen in the browser before information is sent to a server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly