Garrett Henry Garrett Henry - 3 months ago 6x
HTML Question

Why doesn't the pattern or required attribute work?

I am currently doing homework, and following the instructions the book gives me, but I can't get the required or pattern tags to work. I am creating a survey form, and trying to make an error come up when the user doesn't type in their name, receipt number, or email. Here is a portion of it.

<label for"receipt">Receipt number *</label>
<input name="receipt" id="receipt"
pattern="^re\-\d{6}$" />


A few things i see

  • the required attribute does not need a value, the existence of the attribute is what makes it required or not.
  • the - does not need to be escaped so use ^re-\d{6}$ for the pattern attribute
  • the issue with the notepad++ is that the language formatting/color-coding is not up-to-date with all the attributes.

<input name="receipt" id="receipt" 
              required pattern="^re-\d{6}$" />