Search code examples
phphtmlattributes

HTML5 email pattern attribute for my school email


I want to make user only enter my school email using pattern attribute. The pattern should look like "[email protected]". XXXXX could be letters (lowercase, uppercase ) or numbers. I have the first part: [a-zA-Z0-9]{5}. I am not sure how to add @auburn.edu

    <div class="well" style="margin-top: 50px;">
      <form method="POST" action="index.php">
            <div class="form-group row">
            <label for="inputAUEmail" class="col-sm-2 col-form-label">Auburn Email*</label>
            <div class="col-sm-10">
            <input type="text" class="form-control" id="student_email" name="student_email" placeholder="[email protected]" required pattern="[a-zA-Z0-9]{5}">
            </div>
            </div>
    
        <div class="form-group row">
          <div class="offset-sm-2 col-sm-10" style="margin-top: 10px;">
                <button type="submit" class="btn btn-primary" name="submit">Submit</button>
              </div>
        </div>
    </form>
</div>

Solution

  • You can use the following regex expression:

    Expression:

    pattern="[a-zA-Z0-9]{5}@(auburn\.edu)$"
    
    • @ = value must have '@' char in it
    • (auburn.edu) = regex group for a specified string
    • $ = to tell end of string