How to do validation in HTML forms

0

How are mandatory fields made in HTML forms (those that commonly use an asterisk * to indicate mandatory)? Is there any parameter directly in the input tag? If not, how is validation done (for example, at the time the user clicks send, if the field was not filled out a message is displayed and the form is not sent)?

    
asked by anonymous 22.03.2016 / 18:55

2 answers

2

Use the required attribute:

<input type="text" name="obrigatorio" required>

Abcs!

    
22.03.2016 / 18:58
3

Just put the required in the input tag

<form>
  <input type="text" name="name" required />
  <input type="submit" />
</form>
    
22.03.2016 / 18:57